Last active
November 28, 2017 09:06
-
-
Save yassineAlouini/831a56ae0133251dc9e7a5248dc6aa6a to your computer and use it in GitHub Desktop.
A utility function to localize a UTC timestamp DataFrame column
This file contains hidden or 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 pytz | |
def localize_datetime(input_df, timezone, tms_col): | |
""" | |
Convert datetime column from UTC to another timezone. | |
""" | |
tmz = pytz.timezone(timezone) | |
df = input_df.copy() | |
return (df.set_index(tms_col) | |
.tz_localize(pytz.utc) # UTC time | |
.tz_convert(tmz) # Timezone time | |
.reset_index()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment