I have a data set with a date column, I have run this code:
start_date = pd.to_datetime('01-07-2023')
end_date = pd.to_datetime('30-06-24')
filtered_data = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]
But it returns this error:
File "C:UsersJPAppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagespandascoreindexesbase.py", line 3812, in get_loc
raise KeyError(key) from err
KeyError: 'Date'
However the Key Date does exist in my dataframe
I expect a return of entries that fall in within the filtered data range
New contributor
John Paul Kintu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1