'Convert string to_datetime with wrong place day and month
I have a dataset like this
df = pd.DataFrame({'time': ('08.02.2020', '21.02.2020', '2020.05.04')})
df
I do
pd.to_datetime(df['time'])
0 2020-08-02
1 2020-02-21
2 2020-05-04
Name: time, dtype: datetime64[ns]
But the first row must be
0 2020-02-08
If i do
pd.to_datetime(df['time']).dt.strftime('%d-%m-%Y')
0 02-08-2020
1 21-02-2020
2 04-05-2020
Name: time, dtype: object
Again 02-08-2020 instead of 08-02-2020
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|