I have a dataframe with the following structure:
import numpy as np
import pandas as pd
df = pd.DataFrame(
dict(
time=pd.DatetimeIndex([
'2018-10-28 01:30:00',
'2018-10-28 02:00:00',
'2018-10-28 02:30:00',
'2018-10-28 02:00:00',
'2018-10-28 02:30:00',
'2018-10-28 03:00:00',
'2018-10-28 03:30:00']),
zone=np.random.choice(['Europe/Madrid', 'Europe/London', 'Europe/Paris'], 7)
)
)
I want to apply tz_localize row-wise, something like:
df.assign(
time_localized=df.time.dt.tz_localize(df["zone"])
)
it returns
TypeError: <class 'pandas.core.series.Series'>
how can I apply row-wise tz_localize?
I am also interested in doing the reverse operation, moving from UTC to each of the time zones in the rows.
Thanks!