Steadily Climbing Athletes
Problem
You are given two DataFrames. `athletes` has columns `athlete_id` and `full_name`. `race_results` has columns `result_id`, `athlete_id`, `race_day`, and `fitness_score`; each row is one race result for an athlete.
Find every athlete whose three most recent races (by `race_day`) show a strictly increasing `fitness_score`. Only consider athletes with at least three recorded races. Report the climb amount as the score of the latest of those three races minus the score of the earliest.
Return a DataFrame with columns `athlete_id`, `full_name`, and `gain`, ordered by `gain` descending, then `full_name` ascending.
Input data
Example rows — the live problem includes the full dataset.
| athlete_id | full_name |
|---|---|
| 1 | Mara Velasquez |
| 2 | Theo Nakamura |
| 3 | Priya Anand |
| 4 | Owen Castellano |
| 5 | Lena Fischer |
| result_id | athlete_id | race_day | fitness_score |
|---|---|---|---|
| 1 | 1 | 2024-02-03 | 40 |
| 2 | 1 | 2024-03-09 | 55 |
| 3 | 1 | 2024-04-12 | 60 |
| 4 | 1 | 2024-05-18 | 72 |
| 5 | 2 | 2024-02-01 | 50 |
Expected output
Your answer should return 2 rows with the columns athlete_id, full_name, gain.
Starter code (Pandas (Python))
import pandas as pd
def steadily_climbing_athletes(athletes, race_results) -> pd.DataFrame:
# Your code here
return athletesSolve 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