在数据框 groupby 上绘制子条形图

时间:2021-01-30 10:07:50

标签: python pandas pandas-groupby

嗨,我在数据框 groupby 之后绘制子条形图时遇到了一些问题

post groupby,数据如下:

enter image description here

我尝试了以下方法来创建条形图。

df_temp[df_temp.index =='ABC'].unstack().plot.bar(figsize=(10,2))

enter image description here

如何绘制条形图,其中 x 轴是日期,y 轴是计数,每一行(ABC 和 EFG)都是它自己的子图(垂直堆叠)

下面的例子

enter image description here

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

感谢@r-beginnners

#remove the multi-level column    
df.columns = df.columns.droplevel()  

#plot the sub-plots
# if y-axis scale to be the same, use sharey=True 
df.T.plot(subplots=True, layout=(2,1), kind='bar', sharey=True)
相关问题