2015-04-04 171 views
1

我想繪製TE以下數據至極是唯一的文本代碼大熊貓繪製一組

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

這應該工作得到一個類似於您的評論中鏈接的分組條形圖:

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

我不希望他們被加入了,我想是這樣http://pandas.pydata.org /pandas-docs/version/0.15.0/_images/bar_plot_multi_ex.png – rienverbeke 2015-04-04 20:45:31

+0

我的錯誤,請參閱我更新的答案。 – 2015-04-04 21:03:15

+0

非常感謝 – rienverbeke 2015-04-04 21:09:39