Home > database >  How to avoid Wrong recognition and Convention of Date - from String to Date format in Pandas Columns
How to avoid Wrong recognition and Convention of Date - from String to Date format in Pandas Columns

Time:08-08

I have a Pandas column with dates as strings "12-10-2021 00:00" and "13-10-2021 00:00" i am using df['Date'] = df['Date'].astype('datetime64[ns]') output is coming as dates 2021-12-10 and 2021-10-13 where months and days are not converted correctly. enter image description here

How do i get the dates correctly as

2021-10-12

2021-10-13

CodePudding user response:

You can use

df['Date'] = pd.to_datetime(df['Date'], dayfirst=True)
  • Related