Reputation: 97
I want to set the index of a pandas dataframe by a list which includes dates in a common format YYYY:MM:DD hh:mm:ss
index=df.index.tolist()
df2=df1.set_index(index)
the outcome
KeyError: '2011-06-21 00:00:00'
I tried to
df2=df1.set_index(str(index))
because of the backspace between date and time but the result was a KeyError for every single date in my index list.
Upvotes: 1
Views: 420
Reputation: 863166
Add []
for nested list, else it looking for columns names:
df2 = df.set_index([index])
Upvotes: 1