Next-Day Return Rate at a Climbing Gym
Problem
A climbing gym logs every member visit.
DataFrame: `gym_visit` (from `gym_visit.csv`)
| Column | Type |
|-------------|--------|
| climber_id | int |
| wall_id | int |
| visit_day | object |
| routes_done | int |
Each row records that a climber visited the gym on a given day, used some wall, and completed some number of routes (possibly 0). `(climber_id, visit_day)` is unique.
Report the **share** of climbers who came back on the day immediately after their very first visit: among all distinct climbers, how many had a visit on the calendar day right after their earliest visit day, divided by the total number of distinct climbers. Round to **2 decimal places** and label the column `return_rate`.
**Example**
| climber_id | wall_id | visit_day | routes_done |
|------------|---------|------------|-------------|
| 7 | 2 | 2021-04-01 | 4 |
| 7 | 2 | 2021-04-02 | 6 |
| 8 | 3 | 2022-09-10 | 1 |
| 9 | 1 | 2021-04-02 | 0 |
| 9 | 5 | 2023-01-15 | 3 |
Only climber 7 returned on the day after their first visit (Apr 1 -> Apr 2), so the answer is 1 / 3 = 0.33.
Input data
Example rows — the live problem includes the full dataset.
| climber_id | wall_id | visit_day | routes_done |
|---|---|---|---|
| 7 | 2 | 2021-04-01 | 4 |
| 7 | 2 | 2021-04-02 | 6 |
| 8 | 3 | 2022-09-10 | 1 |
| 9 | 1 | 2021-04-02 | 0 |
| 9 | 5 | 2023-01-15 | 3 |
Expected output
Your answer should return 1 row with the columns return_rate.
Starter code (Pandas (Python))
import pandas as pd
def next_day_return(gym_visit: pd.DataFrame) -> pd.DataFrame:
# Your code here
return gym_visitSolve 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