
Busiest hour per city
hardBusiest 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 Name | Type |
|---|---|
| request_id | int64 |
| city | str |
| requested_at | str |
| surge_multiplier | float64 |
ride_requestsExample Input
| request_id | city | requested_at | surge_multiplier |
|---|---|---|---|
| 1 | San Francisco | 2024-09-06 08:05:00 | 1 |
| 2 | Chicago | 2024-09-06 07:45:00 | 1 |
| 3 | San Francisco | 2024-09-06 08:20:00 | 1.2 |
| 4 | Miami | 2024-09-06 21:10:00 | 1 |
| 5 | San Francisco | 2024-09-06 17:40:00 | 1.5 |
| 6 | Chicago | 2024-09-06 17:05:00 | 1.3 |
| 7 | Miami | 2024-09-06 22:15:00 | 1.4 |
| 8 | San Francisco | 2024-09-06 08:45:00 | 1.2 |
| 9 | Chicago | 2024-09-06 17:30:00 | 1.3 |
| 10 | Miami | 2024-09-06 22:40:00 | 1.6 |
| 11 | San Francisco | 2024-09-06 18:10:00 | 1.1 |
| 12 | Chicago | 2024-09-06 08:15:00 | 1 |
| 13 | Miami | 2024-09-06 22:55:00 | 1.8 |
Example Output
| city | busiest_hour | requests |
|---|---|---|
| Chicago | 17 | 2 |
| Miami | 22 | 3 |
| San Francisco | 8 | 3 |
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.
Company
Lyft
Difficulty
hard
Topic
dates
Language
Pandas
Your code
Loading Python in the background. You can start writing.