2016-11-19 55 views
0

我有一个数据透视表(IE):如何排序熊猫数据透视表中的值并绘制它们?

City     Atlanta  New York Chicago 
Region name    Slow  Grid  Fathe 

2010-01     1   2   3 
2010-02     3   15   23 
...         ... 
2016-01     12   1   0 

当我尝试用下面的绘制一些值:

pivot.ix['2016-01'].plot(kind='barh', 
         figsize=(7, 10), 
         width=0.8, 
         fontsize=10, 
         colormap='autumn') 

我得到如下图: enter image description here

如何更改代码以增加绘制此图表?

回答

3

在pivot.ix []和.plot()调用之间添加.sort_values()将在绘制之前对.ix []返回的Series进行排序,并且应该给出您想要的结果。

pivot.ix['2016-01'].sort_values().plot(kind='barh', 
             figsize=(7, 10), 
             width=0.8, 
             fontsize=10, 
             colormap='autumn')