The error is clear and the problem lay in
When do
To show a example.
df
Dataframe.When do
index=df["Date"]
means that the Dataframe most have column named Date.To show a example.
import pandas as pd data = { "Name": ["Tom", "nick", "krish", "jack"], "Date": [20, 21, 19, 18], } df = pd.DataFrame(data)
>>> df Name Date 0 Tom 20 1 nick 21 2 krish 19 3 jack 18 >>> df['Date'] 0 20 1 21 2 19 3 18 Name: Date, dtype: int64 >>> df.columns Index(['Name', 'Date'], dtype='object')If eg put a space in Date string it will fail with your error.
>>> df['Date'] Traceback (most recent call last): ..... KeyError: 'Date' # Date most be the exact name and a column in df >>> df.columns Index(['Name', 'Date '], dtype='object')