Skip to content

Instantly share code, notes, and snippets.

@scubamut
Last active January 16, 2025 06:55
Show Gist options
  • Save scubamut/83292ee3034aaff1bb2b0c29937210f7 to your computer and use it in GitHub Desktop.
Save scubamut/83292ee3034aaff1bb2b0c29937210f7 to your computer and use it in GitHub Desktop.
import pandas as pd
# Option 1: Make naive datetimes timezone-aware
# Add timezone to naive datetime
naive_dt = pd.to_datetime('2024-01-01')
aware_dt = naive_dt.tz_localize('UTC') # or any timezone like 'US/Eastern'
# Option 2: Remove timezone from aware datetime
aware_dt = pd.to_datetime('2024-01-01', utc=True)
naive_dt = aware_dt.tz_localize(None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment