Each Member's First Gym Visit
Problem
A gym records every visit by its members.
DataFrame: `visits` (from `visits.csv`)
| Column | Type |
|-------------|--------|
| member_id | int |
| branch_id | int |
| visit_date | object |
| minutes | int |
Each row is one day a member checked in at some branch and trained for a number of minutes.
Write a function that finds the **first visit date** for each member. Return columns `member_id` and `first_visit`, in any order.
Input data
Example rows — the live problem includes the full dataset.
| member_id | branch_id | visit_date | minutes |
|---|---|---|---|
| 1 | 2 | 2021-01-10 | 45 |
| 1 | 2 | 2021-02-04 | 60 |
| 2 | 3 | 2021-03-22 | 30 |
| 3 | 1 | 2021-01-15 | 0 |
| 3 | 4 | 2021-05-09 | 50 |
Expected output
Your answer should return 3 rows with the columns member_id, first_visit.
Starter code (Pandas (Python))
import pandas as pd
def first_visit(visits: pd.DataFrame) -> pd.DataFrame:
# Your code here
return visitsSolve 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