AnalystPath

Each Athlete's Best Event

PandasMediumMid level~10 min

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.

result
athlete_idevent_idpoints
2295
2395
1190
1299
3180

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 result

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