As already answered (Converting time zone pandas dataframe), Pandas provides means to localize datetime
columns (tz_localize
) and convert time zones (tz_convert
) to a predefined time zone. For example:
df["localized_time"] = df.time.tz_localize(pytz.utc).tz_convert("Some/Timezone")
However, both functions accept the time zone itself as an argument. What if the time zone comes from another column in the same data frame? For example:
time timezone ...
0 2022-04-11 12:24:43 "Europe/Paris" ...
1 2022-04-11 04:22:12 "US/Eastern" ...
...
Is there a simple way to combine the "time" column (already a datetime
type) with the time zone taken the "timezone" column (string)?