I am creating a time series as follows:
import pandas as pd
dti = pd.date_range('2020-01-01 00:00', '2021-01-01 00:00', freq='0.25H')
Now, I want to modify this timeseries based on Day Light saving in Europe/Berlin. Meaning: on 29th march 2020 the clocks jumped from 29-03-2020 01:59:59 to 29-03-2020 03:00:00 and on 25th october 2020, the clocks will jump one hour back from 25-10-2020 02:59:59 to 25-10-2020 02:00:00 and so on.
I tried doing:
dti_CEST = dti.tz_localize(tz='Europe/Berlin', ambiguous='infer')
But it throws the following error:
dti_CEST = dti.tz_localize(tz='Europe/Berlin', ambiguous='infer')
Traceback (most recent call last):
File "<ipython-input-3-cb1d671c16a6>", line 1, in <module>
dti_CEST = dti.tz_localize(tz='Europe/Berlin', ambiguous='infer')
File "C:\Users\kashy\Anaconda3\envs\py36\lib\site-packages\pandas\core\accessor.py", line 93, in f
return self._delegate_method(name, *args, **kwargs)
File "C:\Users\kashy\Anaconda3\envs\py36\lib\site-packages\pandas\core\indexes\datetimelike.py", line 813, in _delegate_method
result = operator.methodcaller(name, *args, **kwargs)(self._data)
File "C:\Users\kashy\Anaconda3\envs\py36\lib\site-packages\pandas\core\arrays\datetimes.py", line 1151, in tz_localize
self.asi8, tz, ambiguous=ambiguous, nonexistent=nonexistent
File "pandas\_libs\tslibs\tzconversion.pyx", line 196, in pandas._libs.tslibs.tzconversion.tz_localize_to_utc
AmbiguousTimeError: 2020-10-25 02:00:00
My current timeseries dti:
date
#march
2020-03-29 00:00:00
2020-03-29 00:15:00
2020-03-29 00:30:00
2020-03-29 00:45:00
2020-03-29 01:00:00
2020-03-29 01:15:00
2020-03-29 01:30:00
2020-03-29 01:45:00
2020-03-29 02:00:00
2020-03-29 02:15:00
2020-03-29 02:30:00
2020-03-29 02:45:00
2020-03-29 03:00:00
2020-03-29 03:15:00
2020-03-29 03:30:00
2020-03-29 03:45:00
2020-03-29 04:00:00
# october
2020-10-25 00:00:00
2020-10-25 00:15:00
2020-10-25 00:30:00
2020-10-25 00:45:00
2020-10-25 01:00:00
2020-10-25 01:15:00
2020-10-25 01:30:00
2020-10-25 01:45:00
2020-10-25 02:00:00
2020-10-25 02:15:00
2020-10-25 02:30:00
2020-10-25 02:45:00
2020-10-25 03:00:00
2020-10-25 03:15:00
2020-10-25 03:30:00
2020-10-25 03:45:00
2020-10-25 04:00:00
Desired output
date
#march
2020-03-29 00:00:00
2020-03-29 00:15:00
2020-03-29 00:30:00
2020-03-29 00:45:00
2020-03-29 01:00:00
2020-03-29 01:15:00
2020-03-29 01:30:00
2020-03-29 01:45:00
2020-03-29 03:00:00 #changed here
2020-03-29 03:15:00
2020-03-29 03:30:00
2020-03-29 03:45:00
2020-03-29 04:00:00
2020-03-29 04:15:00
2020-03-29 04:30:00
2020-03-29 04:45:00
2020-03-29 05:00:00
# october
2020-10-25 00:00:00
2020-10-25 00:15:00
2020-10-25 00:30:00
2020-10-25 00:45:00
2020-10-25 01:00:00
2020-10-25 01:15:00
2020-10-25 01:30:00
2020-10-25 01:45:00
2020-10-25 02:00:00
2020-10-25 02:15:00
2020-10-25 02:30:00
2020-10-25 02:45:00
2020-10-25 02:00:00 #changed here
2020-10-25 02:15:00
2020-10-25 02:30:00
2020-10-25 02:45:00
2020-10-25 03:00:00
How can I do this?