条形图lis中的唯一元素

2024-09-26 18:15:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试条形图绘制列表中每个元素的数量:

x=[1,1,2]
list_pd = pd.DataFrame({'DrawnCards':x})
list_pd.head()
list_pd = list_pd.groupby('DrawnCards')['DrawnCards'].count() 

DrawnCards
1    2
2    1
Name: DrawnCards, dtype: int64

plt.bar(list_pd.DrawnCards)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-117-7f4d4efd9a31> in <module>()
----> 1 plt.bar(list_pd.DrawnCards)

C:\Users\mesme\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   2968             if name in self._info_axis:
   2969                 return self[name]
-> 2970             return object.__getattribute__(self, name)
   2971 
   2972     def __setattr__(self, name, value):

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

所以我需要把序列类型改成数据帧吗?我对这个有点迷恋。你知道吗


Tags: nameinself元素列表returnobject绘制

热门问题