AnalystPath

Prime-Time Gym Regulars

PandasMediumMid level~10 min

Problem

You are given one DataFrame `gym_visits` (loaded from `gym_visits.csv`). Each row is a single gym visit, with columns `visit_id`, `member_id`, `checkin_time` (the timestamp the member started), `calories_burned`, and an optional `session_score` from 1 to 5 the member may leave afterwards (NaN when skipped). Find the prime-time regulars, defined by ALL of: the member logged at least 3 visits; at least 60% of their visits started during prime time (morning hours 6, 7, 8 or evening hours 17, 18, 19); the average score over the visits they DID rate is at least 4.0; and they rated at least half of their visits. Return a DataFrame with each qualifying member's `member_id` and their average rated score as `mean_score`, rounded to 2 decimals. Order by `mean_score` descending, then by `member_id` descending.

Input data

Example rows — the live problem includes the full dataset.

gym_visits
visit_idmember_idcheckin_timecalories_burnedsession_score
1102024-04-01 06:30:004205.0
2102024-04-03 18:10:005104.0
3102024-04-05 07:45:003805.0
4102024-04-07 12:00:00300
5202024-04-01 17:05:006004.0

Expected output

Your answer should return 2 rows with the columns member_id, mean_score.

Starter code (Pandas (Python))

import pandas as pd

def find_prime_time_regulars(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