Pandas UTC timestamp to local time based on timezone column
import pandas as pd | |
# Example dataframe | |
tz_df = pd.DataFrame({'timestamp': pd.to_datetime(['2019-10-08 11:20:00+00:00', | |
'2019-10-08 01:20:00+00:00']), | |
'tz': ['cet', 'est']}) | |
# Add local_time | |
tz_df['local_time'] = tz_df.apply(lambda x: x.timestamp.tz_convert(x.tz), axis=1) | |
print(tz_df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment