AnalystPath

Members With Both Plans

PandasEasyJunior level~10 min

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_idmember_idplan_name
11501Yoga
12501Pilates
13501Spin
14502Spin
15502Spin

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 gympasses

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