may
may

Reputation: 1185

Formatting datetime stamp

I have a data frame with an index that is a DateTime stamp. I would like to change it by formatting the index. I have to use strftime to apply but when I used to like this it doesn't work.

df.index = df.index.map(strftime('%Y-%m-%d'))
Error: 'strftime' is not defined

But it work just fine when I do like this:

df1.index[0].strftime('%Y-%m-%d')

I would like to apply for all my index. Suggestions, please?

Upvotes: 2

Views: 57

Answers (1)

jezrael
jezrael

Reputation: 863166

You are close, need strftime:

df.index = df.index.strftime('%Y-%m-%d')

Upvotes: 2

Related Questions