Title: Convert pandas Column's Time Zone
Slug: convert_pandas_column_timezone
Summary: How to convert the time zone of a pandas column/series in Python.
Date: 2017-09-11 12:00
Category: Machine Learning
Tags: Preprocessing Dates And Times
Authors: Chris Albon
In [1]:
# Load libraries
import pandas as pd
from pytz import all_timezones
In [2]:
# Show ten time zones
all_timezones[0:10]
Out[2]:
In [3]:
# Create ten dates
dates = pd.Series(pd.date_range('2/2/2002', periods=10, freq='M'))
In [4]:
# Set time zone
dates_with_abidjan_time_zone = dates.dt.tz_localize('Africa/Abidjan')
# View pandas series
dates_with_abidjan_time_zone
Out[4]:
In [5]:
# Convert time zone
dates_with_london_time_zone = dates_with_abidjan_time_zone.dt.tz_convert('Europe/London')
# View pandas series
dates_with_london_time_zone
Out[5]: