Issue
I have a column in my pandas dataframe which has rows containing the below:
2021-01-04T23:00:00.000+00:00
I would like to split it and keep only the date element and convert the string to a date format:
04/01/2021
I have tried to use split string but I am unable to get to the final stage of then converting to a date format.
Thank you!
Solution
Don't, split. Convert to_datetime
and export to the desired format directly with strftime
:
df['new'] = pd.to_datetime(df['col']).dt.strftime('%d/%m/%Y')
output:
col new
0 2021-01-04T23:00:00.000+00:00 04/01/2021
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.