1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Dates and Times in Python

Exercise

Parsing pairs of strings as datetimes

Up until now, you've been working with a pre-processed list of datetimes for W20529's trips. For this exercise, you're going to go one step back in the data cleaning pipeline and work with the strings that the data started as.

Explore onebike_datetime_strings in the IPython shell to determine the correct format. datetime has already been loaded for you.

Reference
%Y4 digit year (0000-9999)
%m2 digit month (1-12)
%d2 digit day (1-31)
%H2 digit hour (0-23)
%M2 digit minute (0-59)
%S2 digit second (0-59)

Instructions

100 XP
  • Outside the for loop, fill out the fmt string with the correct parsing format for the data.
  • Within the for loop, parse the start and end strings into the trip dictionary with start and end keys and datetime objects for values.