大熊猫策划一组

时间:2015-04-04 20:17:04

标签: 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')
by_element['Alarm tekst'].value_counts().plot(kind='bar')

代码的结果 enter image description here

如何将情节分组为:

enter image description here

1 个答案:

答案 0 :(得分:1)

这应该可以获得类似于评论中链接的分组条形图:

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')