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

Leave a Reply

Your email address will not be published. Required fields are marked *

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