AnalystPath

Class Reservations and Waitlist Counts

PandasMediumMid level~10 min

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.

classes
class_idmax_spots
12
25
31
signups
member_idclass_id
101
111
121
132
142

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 classes

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