Skip to content

Convert YYYYMXX to date in pandas dataframe in Python

Solution

pd.to_datetime(df['Date'], format="%YM%m").dt.strftime('%Y-%m-%d')
Advertisements

Output

0    2021-09-01
1    2021-09-01
2    2021-09-01
Name: Date, dtype: object
See also  Creating Interactive Corona Virus(COVID-19) Tracking Dashboard using Python

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.