think-maths
think-maths

Reputation: 967

Convert the month in uppercase in dataframe on strftime that is operated on Index

I have a piece of code and a line there converts date in format ddMonYY that is 01Jun19

new1 = ((df.index.levels[0] - pd.to_timedelta(7, unit='d')).strftime('%d%b%y') + ' - '+
        df.index.levels[0].strftime('%d%b%y'))

This gives output as 01Jun19

But I want output as 01JUN19 (month uppercase)

I tried using upper() as well as %^b both did not work

output for upper() is that it is not working on index


new1 = ((df.index.levels[0] - pd.to_timedelta(7, unit='d')).strftime('%d%b%y') + ' - '+
        df.index.levels[0].strftime('%d%b%y')).upper()

Error:

   df.index.levels[0].strftime('%d%b%y')).upper()
AttributeError: 'Index' object has no attribute 'upper'

Please provide insight on this

Upvotes: 1

Views: 1229

Answers (1)

jezrael
jezrael

Reputation: 863301

Use Series.str.upper it working same for index and for Series:

df.index.levels[0].strftime('%d%b%y').str.upper()

Upvotes: 1

Related Questions