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.
How do i get the dates correctly as
2021-10-12
2021-10-13
Advertisement
Answer
You can use
df['Date'] = pd.to_datetime(df['Date'], dayfirst=True)