Breakthrough Third Session
Problem
You are given a DataFrame `workout` with columns `athlete_id`, `distance_km`, and `logged_at`. There is no single-column key; the pair `(athlete_id, logged_at)` is unique. Each row is one logged workout for an athlete.
For every athlete, look at their third workout in chronological order (by `logged_at`). Keep that workout only if its `distance_km` is strictly greater than both the athlete's first and second workouts. Return `athlete_id`, the third workout's distance as `breakthrough_distance`, and its timestamp as `breakthrough_at`, ordered by `athlete_id`.
Input data
Example rows — the live problem includes the full dataset.
| athlete_id | distance_km | logged_at |
|---|---|---|
| 1 | 3.00 | 2024-01-01 06:00:00 |
| 1 | 4.50 | 2024-01-03 06:00:00 |
| 1 | 6.20 | 2024-01-05 06:00:00 |
| 2 | 8.00 | 2024-01-02 07:00:00 |
| 2 | 5.00 | 2024-01-04 07:00:00 |
Expected output
Your answer should return 1 row with the columns athlete_id, breakthrough_distance, breakthrough_at.
Starter code (Pandas (Python))
import pandas as pd
def breakthrough_third_session(workout) -> pd.DataFrame:
# Your code here
return workoutSolve 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