AnalystPath

Members Who Held a Pass but Never Checked In

PandasMediumMid level~10 min

Problem

You are given two DataFrames. `passes` has columns `member_id`, `valid_from`, and `valid_to` (dates as `YYYY-MM-DD` strings); each row is a gym pass a member held from `valid_from` through `valid_to` inclusive. `checkins` has columns `member_id` and `visit_date`; each row records a day a member entered the gym.

Count how many distinct members held a pass that was valid at any point during the year 2022 (the pass overlaps the window `2022-01-01` to `2022-12-31`) yet never checked in during 2022. Return one column named `inactive_members`.

Input data

Example rows — the live problem includes the full dataset.

passes
member_idvalid_fromvalid_to
12022-03-012022-09-01
22021-06-012022-02-01
32020-01-012020-12-31
checkins
member_idvisit_date
12022-04-10
22021-07-01

Expected output

Your answer should return 1 row with the columns inactive_members.

Starter code (Pandas (Python))

import pandas as pd

def members_who_held_a_pass_but_never_checked_in(passes, checkins) -> pd.DataFrame:
    # Your code here
    return passes

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