Skip to content
Advertisement

Python Pandas – Datetime gives wrong output only for certain dates

I have a dataframe with a column of dates in the format MMDDYYY. I want to convert the dates into the format YYYY-MM-DD. This works for most dates. But for dates starting with 1, the wrong output is given. In this example, the last 3 rows are wrong. There are many rows so I cannot hardcode the correct value.

JavaScript

My code:

JavaScript

Advertisement

Answer

There you go using string slicing, not the cleanest solution but it does what you require :

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