I managed to create a minimal example that shows the same behaviour:
>>> import pandas as pd
>>> df = pd.DataFrame({'id': [1], 'date': ['2017-10-29 02:04:15']})
>>> df['date'] = pd.to_datetime(df['date'])
>>> df['date'].dt.tz_localize('Europe/Berlin')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/math/.local/lib/python3.5/site-packages/pandas/core/accessor.py", line 88, in f
return self._delegate_method(name, *args, **kwargs)
File "/home/math/.local/lib/python3.5/site-packages/pandas/core/indexes/accessors.py", line 99, in _delegate_method
result = method(*args, **kwargs)
File "/home/math/.local/lib/python3.5/site-packages/pandas/core/indexes/datetimes.py", line 2368, in tz_localize
errors=errors)
File "pandas/_libs/tslibs/conversion.pyx", line 977, in pandas._libs.tslibs.conversion.tz_localize_to_utc
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from '2017-10-29 02:04:15', try using the 'ambiguous' argument
Why does this error occur?
The documentation of tz_localize
doesn't explain this properly.
The error message says that it cannot infer Daylight Saving Time. Now, as probably everybody knows, the change from Daylight Saving Time to normal time occurs at the end of October at 2:00am/3:00am, and in fact, a quick look at the calender tells us that DST change in 2017 was on October, 29th.
The change from Daylight Saving Time to normal time occurs this way:
Therefore, there are two different times that the clock shows 2017-10-29 02:04:15. Or, in other words, the time 2017-10-29 02:04:15 is ambiguous without knowing whether you are talking about DST or not … which is exactly what the error is saying.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With