简体   繁体   English

选择数据透视表列

[英]Select Pivot Table Columns

I have a pivot table like this; 我有一个这样的数据透视表;

                     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
                ...

I can't select index columns. 我无法选择索引列。 How can I select column 'year-month' or 'amount'? 如何选择“年-月”或“金额”列?

year-month         
2015-03-01   
2015-04-01  
2015-05-01  
2015-06-01
...  

Edit 编辑

This doesn't work; 这行不通;

pivot_df['year-month']

One command which is very useful, especially after a pivot table command, is to reset the index: 一个非常有用的命令(尤其是在数据透视表命令之后)是重置索引:

pivot_df.reset_index(inplace=True)

You can also set a specific column to be an index: 您还可以将特定的列设置为索引:

pivot_df.set_index('year-month', inplace=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM