Support Tickets Grouped Into 4-Hour Shifts
Problem
DataFrame `hourly_tickets` has columns `hour_of_day` (1..24) and `ticket_count`. Group the hours into 4-hour shifts where shift number = ceil(hour / 4), i.e. `(hour_of_day + 3) // 4`, and sum `ticket_count` within each shift. Only shifts that contain at least one row appear.
Return columns `shift_no`, `total_tickets`, sorted by `shift_no`.
Input data
Example rows — the live problem includes the full dataset.
hourly_tickets
| hour_of_day | ticket_count |
|---|---|
| 1 | 5 |
| 2 | 3 |
| 4 | 2 |
| 5 | 7 |
| 8 | 1 |
Expected output
Your answer should return 3 rows with the columns shift_no, total_tickets.
Starter code (Pandas (Python))
import pandas as pd
def tickets_by_shift(hourly_tickets) -> pd.DataFrame:
# Your code here
return hourly_ticketsSolve 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