Members With Both Plans
Problem
A boutique gym sells passes under several plan names. You are given a DataFrame `gympasses` with columns `pass_id`, `member_id`, and `plan_name`.
Find every distinct `member_id` that has purchased at least one **Yoga** pass and at least one **Spin** pass. Return one row per qualifying member in a single column `member_id`, ordered by `member_id` ascending.
Input data
Example rows — the live problem includes the full dataset.
gympasses
| pass_id | member_id | plan_name |
|---|---|---|
| 11 | 501 | Yoga |
| 12 | 501 | Pilates |
| 13 | 501 | Spin |
| 14 | 502 | Spin |
| 15 | 502 | Spin |
Expected output
Your answer should return 2 rows with the columns member_id.
Starter code (Pandas (Python))
import pandas as pd
def members_with_both_plans(gympasses) -> pd.DataFrame:
# Your code here
return gympassesSolve 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