question 443 Data Formats & Analytical Workflows · easy
Trips per hour, straight from the file
Write trips_per_hour(csv_path): with one DuckDB query over the CSV file, count trips per pickup hour and return {hour: count} for the hours that have trips. (DuckDB reads pickup_at from the file as a timestamp; hour(pickup_at) extracts the hour.)
Function
trips_per_hour(csv_path)Returnsa dictionary from hour (int) to number of trips (int)
Examples
calltrips_per_hour('trips.csv')returns{0: 11, 1: 3}
calltrips_per_hour('one.csv')returns{13: 1}
calltrips_per_hour('midnight.csv')returns{23: 1, 0: 2}