来自熊猫数据框的Matplotlib绘图图groupby

时间:2018-11-13 06:57:28

标签: python python-3.x pandas matplotlib pandas-groupby

我有一个名为Results.txt的.txt文件,其中包含如下列表

[100.0, 95.42, 97.31, 95.42, 95.17, 95.17, 95.35, 96.24, 95.48]

我使用了Pandas的read_csv函数来读取.txt文件,并将列表放入DataFrame中。

dd = pd.read_csv('Results.txt')

df = pd.DataFrame(result)
df.columns = ['Results']
df

这就是结果

出[6]:

    Results
0    100.00
1     95.42
2     97.31
3     95.42
4     95.17
5     95.17
6     95.35
7     96.24
8     95.48

我知道在为它绘制图形之前需要为DataFrame使用groupby函数,但是它返回了一个错误。

graph = df.groupby('Results').count()
plt.plot(graph)
plt.show()

ZeroDivisionError: integer division or modulo by zero

在绘制图形之前,我是否有任何错过或做错的事情?

2 个答案:

答案 0 :(得分:2)

这应该有效:

df.groupby(['result']).size().plot(kind='bar')

enter image description here

答案 1 :(得分:0)

您在使用groupby函数时出错。试试这个

/src

enter image description here