Search code examples
pythonpandasjupyterdata-mining

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())

I am working in a Jupyter notebook and covid is the name of my dataset. I am trying to preprocess the dataset by removing dates outside a certain range, but I get this error:

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'

It looks like it doesn't recognize the attribute "submission_date", but it's right there. What causes this issue?


Solution

  • As @luigigi said, "its your index, not a column. try covid.index < "2021-05-31". also make sure the type of the index is datetime. it doesnt look like that"

    Thanks a lot!