如果我有一个数据
Date Values
2005-01 10
2005-02 20
2005-03 30
2006-01 40
2006-02 50
2006-03 70
如何更改年份列?像这样
Date 2015 2016
01 10 40
02 20 50
03 30 70
谢谢。
最佳答案
df[['year','month']] = df.Date.str.split('-', expand=True)
df = df.pivot(index='month', columns='year', values='Values')
print (df)
year 2005 2006
month
01 10 40
02 20 50
03 30 70
关于python - 如何从包含年份和月份的单个日期列中为每年创建一个列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40602960/