如何对 pandas pivot table 中的值进行排序并绘制它们?
How to sort values in pandas pivot table and plot them?
我有一个支点table(即):
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')
我得到下图:
如何更改代码以按升序绘制此图?
在 pivot.ix[] 和 .plot() 调用之间添加 .sort_values() 将在绘制之前对 .ix[] 返回的系列进行排序,并且应该给您结果你要。
pivot.ix['2016-01'].sort_values().plot(kind='barh',
figsize=(7, 10),
width=0.8,
fontsize=10,
colormap='autumn')
我有一个支点table(即):
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')
我得到下图:
如何更改代码以按升序绘制此图?
在 pivot.ix[] 和 .plot() 调用之间添加 .sort_values() 将在绘制之前对 .ix[] 返回的系列进行排序,并且应该给您结果你要。
pivot.ix['2016-01'].sort_values().plot(kind='barh',
figsize=(7, 10),
width=0.8,
fontsize=10,
colormap='autumn')