Skip to content

Instantly share code, notes, and snippets.

@erickpeirson
Created August 15, 2019 17:53
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 erickpeirson/327e74fe77e3d5cffbcf479c30eb45f0 to your computer and use it in GitHub Desktop.
Save erickpeirson/327e74fe77e3d5cffbcf479c30eb45f0 to your computer and use it in GitHub Desktop.
import pandas as pd
from datetime import datetime
from pytz import UTC, timezone
ET = timezone('US/Eastern')
s = pd.Series([datetime.now(UTC)]) # This is the same as a column in your dataframe.
def convert_datetime(dt: datetime) -> datetime:
"""Convert a localized datetime to Eastern time."""
return dt.astimezone(ET)
s.apply(convert_datetime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment