多索引的 pandas 图 [英] Pandas Plotting with Multi-Index
本文介绍了多索引的 pandas 图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在DataFrame
上执行groupby.sum()
之后,尝试创建想要的绘图时遇到了一些麻烦.
After performing a groupby.sum()
on a DataFrame
I'm having some trouble trying to create my intended plot.
如何为每个Code
创建一个子图(kind='bar'
),其中x轴是Month
,条形图是ColA
和ColB
?
How can I create a subplot (kind='bar'
) for each Code
, where the x-axis is the Month
and the bars are ColA
and ColB
?
推荐答案
我发现unstack(level)方法可以完美地工作,它的另一个好处是不需要先验知识来了解有多少代码.
I found the unstack(level) method to work perfectly, which has the added benefit of not needing a priori knowledge about how many Codes there are.
df.unstack(level=0).plot(kind='bar', subplots=True)
这篇关于多索引的 pandas 图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文