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.
'Europe/London'
, after which you can then calltz_convert('Europe/Berlin')
this has nothing to do with'Berlin'
, it would fail also if you tried to localise to'Paris'
'2017-10-29 02:04:15 +02:00'
then your code would work