Skip to content
Advertisement

pandas datetime doesn’t convert the dates properly in python

i have a dataframe data

JavaScript

i want to convert the dat column to “YYYY-MM-DD” format which is currently in dd-mm-yy format

Code using

JavaScript

The output of this is coming out to be wrong

JavaScript

Problems

  1. it was supposed to be giving output year as 1968 and not 2068
  2. Months and date are also not coming in proper order

Required Output:

JavaScript

Advertisement

Answer

Solution with replace in callable for test last digits and then use %Y for match years in YYYY format:

JavaScript

Or subtract 100 years if year greater like 2022:

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