Created
October 9, 2019 09:32
-
-
Save jeroenboeye/0b2a92d57d6ace3c832a636f3d64e9cc to your computer and use it in GitHub Desktop.
Pandas UTC timestamp to local time based on timezone column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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