Reputation:
I am having some problems converting a string into a date format. Specifically,
Date
0 31 Ott 2020
1 30 Ott 2020
2 29 Ott 2020
3 28 Ott 2020
4 25 Ott 2020
... ...
73 7 Apr 2020
74 2 Apr 2020
75 27 Mar 2020
76 24 Mar 2020
77 23 Mar 2020
I would like to convert into the format yyyy-mm-dd (e.g. 2020-10-31). I did as follows:
df['New_Date'] = pd.to_datetime(df['Date'], format='%d %B %Y')
but I got this error:
ValueError: time data '31 Ott 2020' does not match format '%d %B %Y' (match)
The date seems to be Italian (Ott=Ottobre)
Upvotes: 0
Views: 211
Reputation: 1077
You can set the locale before you convert the time. here's the table of locales
import locale
locale.setlocale(locale.LC_ALL,'it_IT.UTF-8') # sets to italy but can be any locale
df['New_Date'] = pd.to_datetime(df['Date'], format='%d %B %Y')
Upvotes: 1