runtime
442 / 500
question 442 Data Formats & Analytical Workflows · easy

The cache that forgets timestamps

busiest_hour_cached saves trips to a cache file, reads the cache back, and returns the pickup hour with the most trips (the earliest hour on a tie). The trips it receives have a real datetime column, yet it crashes with AttributeError: Can only use .dt accessor with datetimelike values. Fix the cache so the types survive.

Functionbusiest_hour_cached(trips, path)
tripsa DataFrame whose pickup_at column is already a datetime
Returnsan int hour

Loading your progress…

The cache that forgets timestamps — Python practice · Runtime