AnalystPath

Spot a Gym Check-in Spike

PandasMediumMid level~10 min

Problem

A DataFrame `checkins` records each time a member entered the gym, with columns `entry_id`, `member_id` and `checkin_date`. For May 2025 (check-in dates from 2025-05-01 to 2025-05-28 inclusive) we want members who had a spike: any 7-consecutive-day window in which the member's number of check-ins was at least twice their average weekly check-ins for the month. Define a member's average weekly check-ins as their total May check-ins divided by 4. For each qualifying member return `member_id`, `peak_7day_checkins` (the largest count of check-ins inside any 7-day window that starts on one of their check-in days), and `avg_weekly_checkins`, ordered by `member_id`.

Input data

Example rows — the live problem includes the full dataset.

checkins
entry_idmember_idcheckin_date
112025-05-27
252025-05-06
332025-05-25
432025-05-14
532025-05-06

Expected output

Your answer should return 3 rows with the columns member_id, peak_7day_checkins, avg_weekly_checkins.

Starter code (Pandas (Python))

import pandas as pd

def checkin_spikes(checkins) -> pd.DataFrame:
    # Your code here
    return checkins

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