Spanish Datetime Return Nat
I have a date column with the format 19 dic 2020 23:59 (spanish date) and I want to convert it into a datetime type. df['Time'] = pd.to_datetime(df.Time, format='%d %b %Y %H:%M', e
Solution 1:
I believe this is an error that is associated with pandas' function not supporting other locales such as es_ES
as in your case. I would recommend changing the locale or iterating as is described in these two answers. The first uses a locale change via datetime
and the second recommends using substitution.
Solution 2:
This is neither a pandas nor a locale problem. For one, your strptime
directive is slightly wrong, and second, your input just doesn't match %b
. pd.to_datetime
works fine if you set the correct locale, supply the correct input and set the correct format directive:
import locale
locale.setlocale(locale.LC_ALL, 'es_ES')
import pandas as pd
s = '19 dic 2020 23:59'
print(pd.to_datetime(s.replace('dic', 'dic.'), format='%d %b %Y %H:%M'))
# 2020-12-19 23:59:00
Post a Comment for "Spanish Datetime Return Nat"