为什么 pandas 无法访问我的日期时间属性?

Why can't pandas access my datetime attribute?

print("covid before preprocessing")
print("number of instances: ", covid.shape[0])
print("number of attributes: ", covid.shape[1])
print(covid.head())
print()
covid = covid[(covid.submission_date < "2021-05-31") | (covid.submission_date > "2020-06-01")]
print("covid after preprocessing")
print("number of instances: ", covid.shape[0])
print("number of attributes: ", covid.shape[1])
print(covid.head())

我在 Jupyter notebook 上工作,covid 是我的数据集的名称。我试图通过删除特定范围之外的日期来预处理数据集,但出现此错误:

covid before preprocessing
number of instances:  39900
number of attributes:  3
                state  new_case  new_death
submission_date                           
4/1/2021           CA      2234        154
5/31/2021          CA       644          5
2/6/2020           NE         0          0
7/30/2020          ME        22          2
2/2/2021           MS      1059         13

----> 7 covid = covid[(covid.submission_date < "2021-05-31") | (covid.submission_date > "2020-06-01")]
AttributeError: 'DataFrame' object has no attribute 'submission_date'

它似乎无法识别属性“submission_date”,但它就在那里。是什么原因导致此问题?

正如@luigigi 所说,“它是您的索引,而不是列。尝试 covid.index <“2021-05-31”。还要确保索引的类型是日期时间。它看起来不像那样“

非常感谢!