Examples
Localize local times:
import numpy as np
import pandas as pd
s = pd.Series([1],
index=pd.DatetimeIndex(['2019-09-15 01:30:00']))
s.tz_localize('CET')
Be careful with DST changes. When there is sequential data, pandas can
infer the DST time:
s = pd.Series(range(7), index=pd.DatetimeIndex([
'2019-10-28 01:30:00',
'2019-10-28 02:00:00',
'2019-10-28 02:30:00',
'2019-10-28 02:00:00',
'2019-10-28 02:30:00',
'2019-10-28 03:00:00',
'2019-10-28 03:30:00']))
s.tz_localize('CET', ambiguous='infer')
In some cases, inferring the DST is impossible. In such cases, you can pass an ndarray
to the ambiguous parameter to set the DST explicitly
s = pd.Series(range(3), index=pd.DatetimeIndex([
'2019-10-28 01:20:00',
'2019-10-28 02:36:00',
'2019-10-28 03:46:00']))
s.tz_localize('CET', ambiguous=np.array([True, True, False]))