Title: Handling Time Zones
Slug: handling_time_zones
Summary: How to handle timezones for machine learning in Python.
Date: 2017-09-11 12:00
Category: Machine Learning
Tags: Preprocessing Dates And Times
Authors: Chris Albon
In [2]:
# Load libraries
import pandas as pd
from pytz import all_timezones
In [4]:
# Show ten time zones
all_timezones[0:10]
Out[4]:
In [5]:
# Create datetime
pd.Timestamp('2017-05-01 06:00:00', tz='Europe/London')
Out[5]:
In [6]:
# Create datetime
date = pd.Timestamp('2017-05-01 06:00:00')
In [7]:
# Set time zone
date_in_london = date.tz_localize('Europe/London')
In [8]:
# Change time zone
date_in_london.tz_convert('Africa/Abidjan')
Out[8]: