Mateusz Piskorski
Mateusz Piskorski

Reputation: 55

Formatting datetime in dataframe

I have a dataframe with number of different dates as index:

2005-01-02 
2005-01-03 
2005-01-04 
2005-01-04 
... 
2014-12-30 
2014-12-31

and i want to format them as MM-DD without changing the type to string. Can someone help me with that? And second question: If I do that, can I still use dt.dayofyear?

Upvotes: 0

Views: 32

Answers (1)

BENY
BENY

Reputation: 323226

Simple way

df.index.str[5:]

More common way

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

Upvotes: 2

Related Questions