Busiest hour per city

dates

Busiest hour per city

Lyft Pandas Interview Question

Lyft's operations team schedules extra driver incentives for the hour of the day when each city gets the most ride requests, across all days in the data.

Using the ride_requests DataFrame, find each city, the hour of the day (0 to 23) with the most requests as busiest_hour, and the number of requests in that hour as requests. Each city has one clear busiest hour. Assign the answer to result.

Asked of

  • Data Analyst
  • Analytics Engineer
  • Data Engineer
  • Data Scientist
  • ML Engineer

ride_requestsDataFrame22 rows

Column NameType
request_idint64
citystr
requested_atstr
surge_multiplierfloat64

ride_requestsExample Input

request_idcityrequested_atsurge_multiplier
1San Francisco2024-09-06 08:05:001
2Chicago2024-09-06 07:45:001
3San Francisco2024-09-06 08:20:001.2
4Miami2024-09-06 21:10:001
5San Francisco2024-09-06 17:40:001.5
6Chicago2024-09-06 17:05:001.3
7Miami2024-09-06 22:15:001.4
8San Francisco2024-09-06 08:45:001.2
9Chicago2024-09-06 17:30:001.3
10Miami2024-09-06 22:40:001.6
11San Francisco2024-09-06 18:10:001.1
12Chicago2024-09-06 08:15:001
13Miami2024-09-06 22:55:001.8

Example Output

citybusiest_hourrequests
Chicago172
Miami223
San Francisco83

Explanation

On September 6, San Francisco had three requests between 8 and 9 a.m. and one each in the 5 p.m. and 6 p.m. hours, so its busiest hour is 8, with 3 requests. Three of Miami's four requests came in between 10 and 11 p.m., so its busiest hour is 22.

The example above is a small slice of the data. Your code runs against the full DataFrames.