AnalystPath

Support Tickets Grouped Into 4-Hour Shifts

PandasMediumMid level~10 min

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_dayticket_count
15
23
42
57
81

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_tickets

Solve 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

Related Pandas questions