Skip to content
Advertisement

Pandas: Date Format Changes from mmmyy to YYYY-MM-DD

I have a data frame column in mmmyy format and would like to change in yyyy-mm-dd format.

Input :

JavaScript

Output:

JavaScript

tried: conv = lambda x: datetime.strptime(x, "%b %y")

JavaScript

Advertisement

Answer

Sept doesn’t match the %b format as only 3 letters are valid.

JavaScript

You could fix the string to keep only 3 letters:

JavaScript

or .replace(r'(?<=...)D*', '', regex=True)

output:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement