Python 选择数据透视表列
我有一张这样的透视表Python 选择数据透视表列,python,Python,我有一张这样的透视表 amount product year-month 5 2015-03-01 408.0 2015-04-01 6081.0 2015-05-01 10915.0 2015-06-01 12202.0 2015-07-01 13342.0 2015-08-01 18786.0 2015-09
amount
product year-month
5 2015-03-01 408.0
2015-04-01 6081.0
2015-05-01 10915.0
2015-06-01 12202.0
2015-07-01 13342.0
2015-08-01 18786.0
2015-09-01 9491.0
2015-10-01 6014.0
...
我无法选择索引列。
如何选择“年-月”或“金额”列
year-month
2015-03-01
2015-04-01
2015-05-01
2015-06-01
...
编辑
这不管用
pivot_df['year-month']
一个非常有用的命令,尤其是在透视表命令之后,是重置索引:
pivot_df.reset_index(inplace=True)
还可以将特定列设置为索引:
pivot_df.set_index('year-month', inplace=True)
一个非常有用的命令,尤其是在透视表命令之后,是重置索引:
pivot_df.reset_index(inplace=True)
还可以将特定列设置为索引:
pivot_df.set_index('year-month', inplace=True)