LoslegenKostenlos loslegen

Putting the bike trips into the right time zone

Instead of setting the timezones for W20529 by hand, let's assign them to their IANA timezone: 'America/New_York'. Since we know their political jurisdiction, we don't need to look up their UTC offset. Python will do that for us.

Diese Übung ist Teil des Kurses

Working with Dates and Times in Python

Kurs anzeigen

Anleitung zur Übung

  • Import tz from dateutil.
  • Assign et to be the timezone 'America/New_York'.
  • Within the for loop, set start and end to have et as their timezone (use .replace()).

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Import tz
from ____ import ____

# Create a timezone object for Eastern Time
et = tz.____('America/New_York')

# Loop over trips, updating the datetimes to be in Eastern Time
for trip in onebike_datetimes[:10]:
  # Update trip['start'] and trip['end']
  trip['start'] = trip['start'].____
  trip['end'] = trip['end'].____
Code bearbeiten und ausführen