编辑:解决: 首先需要对值进行排序(感谢@ImportanceOfBeingErnest) df.sort_values(by =“published_at”)
我无法弄清楚为什么这个简单的折线图不能很好地渲染。
数据结构:
df.dtypes
bottom_temperature float64
bottom_humidity float64
top_temperature float64
top_humidity float64
external_temperature float64
published_at datetime64[ns]
external_humidity float64
short_id object
weight float64
dtype: object
数据样本
data.head()
bottom_temperature bottom_humidity top_temperature top_humidity external_temperature published_at external_humidity short_id weight
0 34.48 44.81 33.56 47.62 17.88 2017-10-07 23:11:27 17.88 INT5 NaN
1 34.89 42.89 33.89 43.86 18.06 2017-10-09 03:16:05 18.06 INT5 NaN
2 34.87 41.90 33.81 42.88 18.19 2017-10-09 03:31:41 18.19 INT5 NaN
3 34.79 43.05 33.93 44.68 18.00 2017-10-09 03:00:37 18.00 INT5 NaN
4 34.92 42.53 34.04 44.68 18.19 2017-10-09 03:47:11 18.19 INT5 NaN
图代码:
fig, axarr = plt.subplots()
fig.autofmt_xdate()
plt.plot(df.loc[df['short_id'] == 'INT1']['published_at'], df.loc[df['short_id'] == 'INT1']['bottom_temperature'], label = "Bottom Temperature C")
plt.show()
奇怪的是,在另一个笔记本中,代码运行正常,具有相同的.dtypes