AnalystPath

Each Member's First Gym Visit

PandasEasyJunior level~10 min

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.

visits
member_idbranch_idvisit_dateminutes
122021-01-1045
122021-02-0460
232021-03-2230
312021-01-150
342021-05-0950

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 visits

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