Members Who Held a Pass but Never Checked In
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.
| member_id | valid_from | valid_to |
|---|---|---|
| 1 | 2022-03-01 | 2022-09-01 |
| 2 | 2021-06-01 | 2022-02-01 |
| 3 | 2020-01-01 | 2020-12-31 |
| member_id | visit_date |
|---|---|
| 1 | 2022-04-10 |
| 2 | 2021-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 passesSolve 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