I read CSV-files with ambiguous local time -- ambiguous due to daylight saving time.
When I apply tz_localize() I run in the following error:
AmbiguousTimeError: There are %i dst switches when there should only be 1.
Here is my code to reproduce the error. Note that from 2am to 3am every datetime is a duplicate due to daylight saving time.
index = pd.DatetimeIndex(['2018-10-28 01:00:00', '2018-10-28 01:15:00',
'2018-10-28 01:30:00', '2018-10-28 01:45:00',
'2018-10-28 02:00:00', '2018-10-28 02:00:00',
'2018-10-28 02:15:00', '2018-10-28 02:15:00',
'2018-10-28 02:30:00', '2018-10-28 02:30:00',
'2018-10-28 02:45:00', '2018-10-28 02:45:00',
'2018-10-28 03:00:00', '2018-10-28 03:15:00',
'2018-10-28 03:30:00', '2018-10-28 03:45:00',
'2018-10-28 04:00:00'], freq='infer')
data = list(range(len(index)))
df = pd.DataFrame(data=data,index=index)
df.index = df.index.tz_localize('Europe/Berlin', ambiguous='infer')
I don't quite understand why the error occurs even with parameter ambiguous='infer'.
Does my dataframe have to be sorted in any way?
How can I create sorted data frames with pd.read_csv()
I wish to apply ambiguous='infer' with respect to the order of the CSV file. Precisly I mean: the order of the ambiguous time format helps to differ between summer and winter time.
I would be glad about help for a solution and about a broader explanation. I couldn't find much about how order can play a role in data frames--does it sometimes?