Each Athlete's Best Event
Problem
A decathlon league records the points an athlete scored in each event they competed in, in a DataFrame `result` (`result.csv`).
```text
+------------+------+
| Column | Type |
+------------+------+
| athlete_id | int |
| event_id | int |
| points | int |
+------------+------+
```
`(athlete_id, event_id)` is unique. Each row is the points an athlete earned in one event.
Write a function that finds, for each athlete, the event in which they scored their highest points, along with that points value. If an athlete's top points are tied across multiple events, pick the event with the smallest `event_id`. Return columns `athlete_id`, `event_id`, and `points`, ordered by `athlete_id` ascending.
Input data
Example rows — the live problem includes the full dataset.
| athlete_id | event_id | points |
|---|---|---|
| 2 | 2 | 95 |
| 2 | 3 | 95 |
| 1 | 1 | 90 |
| 1 | 2 | 99 |
| 3 | 1 | 80 |
Expected output
Your answer should return 3 rows with the columns athlete_id, event_id, points.
Starter code (Pandas (Python))
import pandas as pd
def best_event(result: pd.DataFrame) -> pd.DataFrame:
# Your code here
return resultSolve 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