【发布时间】:2019-03-30 03:31:26
【问题描述】:
我在熊猫中有以下数据框。 date 是两个不同的日期,在本例中为 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
...
现在我想将这个数据绘制成这样的折线图:
尝试过:
df.set_index('date', inplace=True)
df.groupby('time')['percentage'].plot(legend=True)
plt.show()
但总是返回“TypeError: Empty 'DataFrame': no numeric data to plot”
有人可以帮帮我吗?
【问题讨论】:
-
“百分比”的数据类型是什么? df['percentage'] = pd.to_numeric(df['percentage'])