Skip to content

Instantly share code, notes, and snippets.

@jeroenboeye
Created October 9, 2019 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenboeye/0b2a92d57d6ace3c832a636f3d64e9cc to your computer and use it in GitHub Desktop.
Save jeroenboeye/0b2a92d57d6ace3c832a636f3d64e9cc to your computer and use it in GitHub Desktop.
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