Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert "Day_Name Month Day_No. Time Year" to date format?

I have a date column in a df with values like Fri Apr 01 16:41:32 +0000 2022. I want to convert it into proper date column format 01/04/2022 16:41:32. Where 01 is day and 04 is the month.

Any guidance please?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use pandas.to_datetime for getting datetime then with Series.dt.strftime convert to desired format.

import pandas as pd

# example df
df = pd.DataFrame({'date': ['Fri Apr 01 16:41:32 +0000 2022' , 
                            'Sat Apr 02 16:41:32 +0000 2022']})


df['date'] = pd.to_datetime(df['date']).dt.strftime('%d/%m/%Y %H:%M:%S')
print(df)

                  date
0  01/04/2022 16:41:32
1  02/04/2022 16:41:32
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading