AnalystPath

Average Workout Length Before and After Joining

PandasMediumMid level~10 min

Problem

You are given a DataFrame `gym_visits` (loaded from `gym_visits.csv`) with columns `member_id`, `visit_date`, `pass_kind`, and `minutes`. `pass_kind` is one of `'trial'`, `'member'`, or `'lapsed'`, and `minutes` is how long that visit lasted. A member may have many visits.

The gym wants to study members who started on a `trial` pass and later upgraded to a full `member` pass. A member counts as **converted** only if they have at least one `trial` visit and at least one `member` visit.

For each converted member, return their average visit length during the trial phase and during the member phase. Round both averages to two decimals and ignore `lapsed` visits entirely. Return `member_id`, `trial_avg_minutes`, and `member_avg_minutes`, ordered by `member_id`.

Input data

Example rows — the live problem includes the full dataset.

gym_visits
member_idvisit_datepass_kindminutes
12024-01-01trial45
12024-01-02trial30
12024-01-05trial60
12024-01-10member75
12024-01-12member90

Expected output

Your answer should return 3 rows with the columns member_id, trial_avg_minutes, member_avg_minutes.

Starter code (Pandas (Python))

import pandas as pd

def converted_member_averages(gym_visits) -> pd.DataFrame:
    # Your code here
    return gym_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