Working with Dates and Times in Python
Learn to parse, calculate and plot dates and times in Python and pandas, including time zones and daylight saving, using hurricane and bike trip data.
Time-stamped data hides traps that ordinary numbers do not: day and month boundaries, clocks set to different time zones, and the hour that vanishes or repeats when daylight saving begins or ends. Python offers tools for each of these, and the lessons put them to work on two real datasets: the dates of hurricanes striking Florida and the trips of a single shared bike in Washington, D.C. You count events, measure the time between them, and chart how activity changes over time.
What You Will Achieve
- Do arithmetic on Python date objects to find the weekday of an event or the days between two events
- Parse text into datetimes and write them back out in ISO format or a friendlier style
- Attach the correct UTC offset to a timestamp and spot ambiguous times around daylight saving changes
- Load trip records into pandas, then group and resample them to compare riders over time
Program Overview
Dates and Calendar Math
Python date objects meet the record of hurricanes hitting Florida since 1950, with date arithmetic and clear ways to format dates.
- Date objects and weekdays
- Subtracting dates and counting events per month
- Sorting a list of dates
- Formatting dates as strings
Datetimes, Durations and Time Zones
One bike’s trips in Washington, D.C. carry the practice of combining dates with times and placing each ride in the right time zone.
- Parsing and printing datetimes, including ISO format with strftime()
- Unix timestamps, ride durations and average trip time
- UTC offsets and the dateutil time zone database
- Daylight saving transitions and ambiguous times with fold
Datetime Data in Pandas
The bike data returns with station and membership details, loaded into pandas for summaries, grouping and plots by time.
- Reading a CSV file with date columns
- Timedelta columns and datetime summaries
- Grouping and resampling with groupby() and resample()
- Datetime methods and time zones in pandas
Certificate Awarded (Paid)
Job Outlook
These skills apply wherever Python code handles timestamped records, such as analyzing event logs and trip data, reporting on activity over time, and cleaning data collected across several time zones.
Good for: Analysts who keep getting odd results when their Python data includes dates, durations or records logged in different time zones.
Keep in mind: Three of the four chapters work in standard Python with the datetime module and dateutil; pandas methods appear only in the final chapter.
Bottom line: Its lessons on daylight saving and ambiguous clock times take on the date problem that causes the most trouble, using real bike trip records.
Frequently Asked Questions
Which datasets are the exercises built on?
The first chapter uses the dates of every hurricane to hit Florida since 1950. The rest of the course follows the trips of one shared bike in Washington, D.C., and the pandas chapter adds each ride's stations and whether the rider held a yearly membership.
Which time zone library does the course use?
Time zone work relies on the dateutil library alongside Python's own datetime tools. You set time zones on datetimes, read UTC offsets and pull up-to-date zone data from its time zone database, and the final chapter repeats the idea with pandas.
How does the course handle the repeated hour when clocks fall back?
The lessons on ending daylight saving show how to find ambiguous datetimes, the clock times that occur twice in one night, and how to clean such data with the fold setting so each ride lands on the right hour.


There are no reviews yet.