基于matplotlib的Pandas groupby柱状图

2024-09-30 06:14:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个列上执行groupby的datafrme:

ax = df_all.groupby(['Component', 'SubComponent' ])['SubComponent'].count()

给我这个:

^{pr2}$

现在我想把它做成一个柱状图。 每个条形图将是组件,每个组件将划分在子组件上,显示每个子组件的出现次数,这些子组件具有不同的颜色。在

有没有简单的方法来完成它matplotlib.pyploy? 在

谢谢, 提交


Tags: 方法df颜色count组件allax次数
1条回答
网友
1楼 · 发布于 2024-09-30 06:14:55

您可以将^{}^{}一起使用:

print (ax.unstack())
SubComponent  First  Second  Third
Component                         
A                 1       4     15
B                 6       2      1

ax.unstack().plot.bar(stacked=True)

graph


^{pr2}$

graph3

注意:

What is the difference between size and count in pandas?

相关问题 更多 >

    热门问题