I am working with Nifty index data and I want to slice the dataframe for visualization based on two dates. But I'm getting a type error as "TypeError: cannot do slice indexing on Int64Index with these indexers [2020-03-20 00:00:00] of type Timestamp"
Code:
stdt = pd.to_datetime('20-03-2020')
enddt =pd.to_datetime('14-02-2020')
df['Date'] = pd.to_datetime(df['Date'])
data=df['Date'].between_time(stdt,enddt)
df['nifty'][stdt:enddt].plot(color = "blue")
plt.show()
I tried using between_time and index slicing but I'm getting same error. Is there any way to slice index based on timestamp? Or please let me know the mistake in my code. Any suggestions will be really helpful.