Prime-Time Gym Regulars
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.
| visit_id | member_id | checkin_time | calories_burned | session_score |
|---|---|---|---|---|
| 1 | 10 | 2024-04-01 06:30:00 | 420 | 5.0 |
| 2 | 10 | 2024-04-03 18:10:00 | 510 | 4.0 |
| 3 | 10 | 2024-04-05 07:45:00 | 380 | 5.0 |
| 4 | 10 | 2024-04-07 12:00:00 | 300 | |
| 5 | 20 | 2024-04-01 17:05:00 | 600 | 4.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_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