Busiest Scan Hour per Warehouse Zone
Problem
DataFrame `scan_event` has columns `scanner_id`, `parcel_id`, `scanned_at` (a timestamp), and `zone`. For each zone, find the hour of day (0..23) with the most scans. Use RANK-style ties: if several hours share the top count within a zone, return all of them.
Return columns `zone`, `busy_hour`, `scan_count`, sorted by `busy_hour` descending then `zone` descending.
Input data
Example rows — the live problem includes the full dataset.
scan_event
| scanner_id | parcel_id | scanned_at | zone |
|---|---|---|---|
| 1 | 100 | 2024-04-01 09:05:00 | Inbound |
| 1 | 101 | 2024-04-01 09:40:00 | Inbound |
| 2 | 102 | 2024-04-01 14:10:00 | Inbound |
| 3 | 103 | 2024-04-01 14:20:00 | Packing |
| 3 | 104 | 2024-04-01 14:55:00 | Packing |
Expected output
Your answer should return 2 rows with the columns zone, busy_hour, scan_count.
Starter code (Pandas (Python))
import pandas as pd
def busiest_scan_hour(scan_event) -> pd.DataFrame:
# Your code here
return scan_eventSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock