1

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.

1 Answer 1

1

Add [] for nested list, else it looking for columns names:

df2 = df.set_index([index])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.