Reputation: 543
I have a Pandas dataframe, where the column 'BIRTHDAY' is a column that has a date stored like yyyymmdd, something like this:
id | BIRTHDAY
1 | 19940514
2 | 19890627
3 | 19560101
I would like to turn the column BIRTHDAY into the format dd/mm/yyyy. So the final output would be something like:
id | BIRTHDAY
1 | 14/05/1994
2 | 27/06/1989
3 | 01/01/1956
How can I do it in Pandas?
Upvotes: 0
Views: 304
Reputation: 862591
Use to_datetime
with Series.dt.strftime
and specify input and ouput format:
df['BIRTHDAY'] = pd.to_datetime(df['BIRTHDAY'], format='%Y%m%d').dt.strftime('%d/%m/%Y')
print (df)
id BIRTHDAY
0 1 14/05/1994
1 2 27/06/1989
2 3 01/01/1956
Upvotes: 3