Skip to content

Instantly share code, notes, and snippets.

@HumanRupert
Created June 11, 2021 13:41
Show Gist options
  • Save HumanRupert/9f9f53f9188e052386f55e0f5fc01a4c to your computer and use it in GitHub Desktop.
Save HumanRupert/9f9f53f9188e052386f55e0f5fc01a4c to your computer and use it in GitHub Desktop.
def convert_date_cols(df: pd.DataFrame) -> pd.DataFrame:
"""Given a dataframe, adds UTC timezone to all columns that have date in their names."""
for col in df.columns:
if("date" in col.lower()):
df[col] = pd.to_datetime(df[col]).dt.tz_localize("UTC")
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment