0
0
Pandasdata~30 mins

Timezone handling basics in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Timezone handling basics
📖 Scenario: You work for a travel company that records flight departure times in UTC. You want to convert these times to the local timezone of the departure city to make it easier for customers to understand.
🎯 Goal: Learn how to create timezone-aware datetime data using pandas, convert between timezones, and display the results.
📋 What You'll Learn
Create a pandas Series with UTC datetime values
Create a timezone variable for the local timezone
Convert the UTC datetime Series to the local timezone
Print the converted datetime Series
💡 Why This Matters
🌍 Real World
Travel companies, airlines, and event planners often need to convert times between UTC and local timezones for scheduling and communication.
💼 Career
Understanding timezone handling is important for data analysts and data scientists working with time series data across different regions.
Progress0 / 4 steps
1
Create a pandas Series with UTC datetime values
Import pandas as pd and create a pandas Series called utc_times with these exact datetime strings: '2024-01-01 12:00', '2024-01-01 15:00', '2024-01-01 18:00'. Convert these strings to datetime with timezone set to UTC using pd.to_datetime(...).tz_localize('UTC').
Pandas
Need a hint?

Use pd.to_datetime to convert strings to datetime, then use .tz_localize('UTC') to set the timezone.

2
Create a timezone variable for the local timezone
Create a variable called local_tz and set it to the string 'America/New_York' to represent the local timezone.
Pandas
Need a hint?

Just assign the string 'America/New_York' to the variable local_tz.

3
Convert the UTC datetime Series to the local timezone
Create a new pandas Series called local_times by converting utc_times to the timezone stored in local_tz using the .tz_convert(local_tz) method.
Pandas
Need a hint?

Use utc_times.tz_convert(local_tz) to convert the timezone.

4
Print the converted datetime Series
Print the local_times Series to display the datetime values in the local timezone.
Pandas
Need a hint?

Use print(local_times) to show the converted times.