Python 一群熊猫

Python 一群熊猫,python,pandas,Python,Pandas,我想绘制以下数据,这是一个独特的文本计数 Element Motor 1 thermiek 15 tijd te lang 9 Motor 2 thermiek 12 tijd te lang 3 Motor 3 thermiek 5 tijd te lang 4 dtype: int64 by_element = data.groupby

我想绘制以下数据,这是一个独特的文本计数

Element              
Motor 1  thermiek        15
         tijd te lang     9
Motor 2  thermiek        12
         tijd te lang     3
Motor 3  thermiek         5
         tijd te lang     4
dtype: int64

by_element = data.groupby('Element')
by_element['Alarm tekst'].value_counts().plot(kind='bar')
代码结果

如何使绘图按如下方式分组:


这应该可以得到一个分组条形图,类似于您评论中链接的条形图:

gb = df.groupby(['Element','Alarm tekst'])
gb['Alarm tekst'].count().unstack().plot(kind = 'bar')
对聚合条的原始建议:

您应该包括
agg()
函数来计算总值

data.groupby('Element').agg('count').plot(kind = 'bar')
如果第二列已按术语求和,则可以使用
agg(numpy.sum)

import numpy    
data.groupby('Element').agg(numpy.sum).plot(kind = 'bar')

我不想把它们加起来,我想要这样的东西