我想绘制以下数据,这是唯一文本的计数
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')
关于python - Pandas 绘制一组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29450999/