[英]plot data from a pandas dataframe in a line graph
I have the folowing dataframe in pandas. 我在熊猫中有以下数据框。 The date are two diffrent dates, in this case the 16th and 17th Time will go from 00:00 to 24:00 after that it will be the next day :-) And percentage will go from 100 to 0.
日期是两个不同的日期,在这种情况下,第16和17 时间将从第二天的00:00到24:00 :-) 百分比将从100变为0。
date time percentage
2018-08-16 00:00 36
2018-08-16 00:01 37
2018-08-16 00:01 38
2018-08-16 00:03 39
2018-08-16 00:03 40
2018-08-16 00:04 41
2018-08-16 00:05 42
2018-08-16 00:05 43
2018-08-16 00:06 44
2018-08-16 00:07 45
2018-08-16 00:07 46
2018-08-16 00:08 47
...
2018-08-17 07:24 95
2018-08-17 07:25 94
2018-08-17 07:25 94
2018-08-17 07:32 95
2018-08-17 07:43 96
2018-08-17 07:52 97
...
Now i would like to plot this dat in a line graph like this: 现在我想在这样的线图中绘制此数据:
Tried something with: 尝试使用以下方法:
df.set_index('date', inplace=True)
df.groupby('time')['percentage'].plot(legend=True)
plt.show()
But alway retrurn with a "TypeError: Empty 'DataFrame': no numeric data to plot" 但是总是以“ TypeError:空的'DataFrame':没有要绘制的数字数据”来回退
Can somebody help me? 有人可以帮我吗?
This should do: 应该这样做:
df.percentage=df.percentage.astype(int)
for i in df.date.unique():
aux=df[df.date==i]
plt.plot(aux.time,aux.percentage)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.