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 | |
|---|---|
| %Y | 4 digit year (0000-9999) |
| %m | 2 digit month (1-12) |
| %d | 2 digit day (1-31) |
| %H | 2 digit hour (0-23) |
| %M | 2 digit minute (0-59) |
| %S | 2 digit second (0-59) |
Questo esercizio fa parte del corso
Working with Dates and Times in Python
Istruzioni dell'esercizio
- Outside the
forloop, fill out thefmtstring with the correct parsing format for the data. - Within the
forloop, parse thestartandendstrings into thetripdictionary withstartandendkeys anddatetimeobjects for values.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Write down the format string
fmt = "____"
# Initialize a list for holding the pairs of datetime objects
onebike_datetimes = []
# Loop over all trips
for (start, end) in onebike_datetime_strings:
trip = {'start': datetime.____(____, ____),
'end': datetime.____(____, ____)}
# Append the trip
onebike_datetimes.append(trip)