I can't understand why I'm getting KeyError: Timestamp('...') when using loc on date index.
With given df: dtypes are datetime64[ns], int, int
, DATE1 is index
DATE1 VALUE2 VALUE3
2021-08-20 00:00:00 11 424
2021-08-21 00:00:00 22 424
2021-08-22 00:00:00 33 424
2021-08-23 00:00:00 44 242
I'm trying to use loc on index like this:
start_date = date(2021-08-20)
end_date = date(2021-08-23)
df = df.loc[start_date:end_date]
and this is working fine. I'm getting 4 records. However when I do this:
start_date = date(2021-08-20)
end_date = date(2021-08-24) #end_date is higher than values in dataframe
df = df.loc[start_date:end_date]
I'm getting KeyError: KeyError: Timestamp('2021-08-24 00:00:00')
. Could someone point me how to resolve this?