Class Reservations and Waitlist Counts
Problem
You are given two DataFrames. `classes` (from `classes.csv`) has columns `class_id` (the primary key) and `max_spots` (how many members the studio room physically holds). `signups` (from `signups.csv`) has columns `member_id` and `class_id`; each row is one member signing up for one class. Sign-ups beyond `max_spots` go onto a waitlist.
For every class, report `class_id`, `reserved_cnt` (members who got a confirmed spot, capped at `max_spots`), and `waitlist_cnt` (members who overflowed onto the waitlist, or 0 if none). Include classes with no sign-ups. Order by `class_id`.
Input data
Example rows — the live problem includes the full dataset.
| class_id | max_spots |
|---|---|
| 1 | 2 |
| 2 | 5 |
| 3 | 1 |
| member_id | class_id |
|---|---|
| 10 | 1 |
| 11 | 1 |
| 12 | 1 |
| 13 | 2 |
| 14 | 2 |
Expected output
Your answer should return 3 rows with the columns class_id, reserved_cnt, waitlist_cnt.
Starter code (Pandas (Python))
import pandas as pd
def class_reservations_and_waitlist(classes, signups) -> pd.DataFrame:
# Your code here
return classesSolve 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