AnalystPath

Members Who Booked Yoga and Spin but Not Boxing

PandasMediumMid level~10 min

Problem

A fitness studio records every class a member books.

`members` (`members.csv`): `member_id`, `member_name` — one member per row.

`bookings` (`bookings.csv`): `booking_id`, `member_id`, `class_name` — each row is one class booking by a member.

Return the `member_id` and `member_name` of every member who has booked both the `Yoga` class and the `Spin` class but has **never** booked the `Boxing` class. Return the rows ordered by `member_id`.

Input data

Example rows — the live problem includes the full dataset.

members
member_idmember_name
1Priya
2Marco
3Elena
4Theo
bookings
booking_idmember_idclass_name
101Yoga
201Spin
301Pilates
401Boxing
502Yoga

Expected output

Your answer should return 1 row with the columns member_id, member_name.

Starter code (Pandas (Python))

import pandas as pd

def yoga_and_spin_not_boxing(members: pd.DataFrame, bookings: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return members

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