如何在同一张图中绘制几个计数器?

时间:2020-02-11 11:33:52

标签: python-3.x data-visualization

我有一个带有类,集合大小和一个词汇表计数器的数据框:

>>> df[["Q",'S04Q02']].groupby('S04Q02')['Q'].sum()
Class
Other:                  {'Size': 1, 'employed': 1, 'in': 16, 'the': ...
PSOE:                   {'Size': 24, 'unemployed': 25, '': 4217, 'be...
UNDI:                   {'Size': 27, 'self': 7, 'employed': 25, '': ...
PP:                     {'Size': 6, 'self': 1, 'employed': 8, '': 89...
Ciudadanos:             {'Size': 34, 'unemployed': 35, '': 4975, 'pe...
Podemos:                {'Size': 5, 'employed': 11, 'in': 126, 'the'...

我想代表它。最好的方法是什么?

我试图制作一个循环图和条形图。这不是最佳选择,因为它无法帮助我进行比较:

for row in counters.iterrows():
    plt.bar(row.keys(), row.values())

但是得到了:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-128-fdd41c7f0ffa> in <module>
----> 1 for row in counters.iterrows():
      2     plt.bar(row.keys(), row.values())

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   5065             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5066                 return self[name]
-> 5067             return object.__getattribute__(self, name)
   5068 
   5069     def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'iterrows'

0 个答案:

没有答案