【发布时间】:2021-12-23 18:07:57
【问题描述】:
我有一个以 date_time 列开头的数据框,后跟多个变量,如下所示。
但是,当我尝试绘制时间与变量的关系图时,我收到“'DataFrame' object has no attribute 'date_time'”错误。
fig, ax = plt.subplots(2, 1, figsize=(20,8))
ax[0].plot(df.date_time, df.P1_VWC)
ax[1].plot(df.date_time, df.P2_VWC)
知道为什么我的第一列被忽略了吗?
感谢您的宝贵时间, -博扬
【问题讨论】:
-
date_time 是您的 df 索引,而不是列。要针对索引进行绘图,
ax[0].plot(df.P1_VWC)就足够了。
标签: python pandas dataframe date datetime