Lead Climber on Each Route
Problem
DataFrame: `route_assignment` (`route_assignment.csv`)
```text
+------------+------+
| Column | Type |
+------------+------+
| route_id | int |
| climber_id | int |
+------------+------+
Each row assigns one climber to one route. (route_id, climber_id) is unique.
```
DataFrame: `climber` (`climber.csv`)
```text
+------------+--------+
| Column | Type |
+------------+--------+
| climber_id | int |
| handle | object |
| ascents | int |
+------------+--------+
climber_id uniquely identifies each climber.
```
For each route, find the **lead climber(s)**: the assigned climber(s) with the highest `ascents` on that route. Return columns `route_id` and `climber_id`. If two or more climbers on a route tie for the most ascents, return each of them.
Return the rows in any order.
**Example**
Input — `route_assignment`:
```text
route_id climber_id
1 1
1 2
1 3
2 1
2 4
```
Input — `climber`:
```text
climber_id handle ascents
1 Vega 30
2 Ridge 20
3 Crux 30
4 Pitch 20
```
Output:
```text
route_id climber_id
1 1
1 3
2 1
```
On route 1, climbers 1 and 3 both have 30 ascents (the max), so both lead; on route 2, climber 1 (30) beats climber 4 (20).
Input data
Example rows — the live problem includes the full dataset.
| route_id | climber_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 4 |
| climber_id | handle | ascents |
|---|---|---|
| 1 | Vega | 30 |
| 2 | Ridge | 20 |
| 3 | Crux | 30 |
| 4 | Pitch | 20 |
Expected output
Your answer should return 3 rows with the columns route_id, climber_id.
Starter code (Pandas (Python))
import pandas as pd
def lead_climber(route_assignment: pd.DataFrame, climber: pd.DataFrame) -> pd.DataFrame:
# Your code here
return route_assignmentSolve 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