Total Parcel Weight per Courier
Problem
A delivery depot tracks every parcel its couriers carry.
`couriers` (`couriers.csv`): `courier_id`, `courier_name` — one courier per row.
`deliveries` (`deliveries.csv`): `delivery_id`, `courier_id`, `weight_kg` — each row is one delivered parcel and the weight the named courier carried.
Report, for every courier, the total weight they delivered as `total_weight`. A courier with no deliveries should report `0`. Order the result by `total_weight` descending; when two or more couriers tie, order those by `courier_name` ascending. Return the columns `courier_name` and `total_weight`.
Input data
Example rows — the live problem includes the full dataset.
| courier_id | courier_name |
|---|---|
| 1 | Mia |
| 2 | Owen |
| 3 | Ava |
| 4 | Noah |
| 7 | Leo |
| delivery_id | courier_id | weight_kg |
|---|---|---|
| 1 | 1 | 120 |
| 2 | 2 | 317 |
| 3 | 3 | 222 |
| 4 | 7 | 100 |
| 5 | 13 | 312 |
Expected output
Your answer should return 7 rows with the columns courier_name, total_weight.
Starter code (Pandas (Python))
import pandas as pd
def total_weight_per_courier(couriers: pd.DataFrame, deliveries: pd.DataFrame) -> pd.DataFrame:
# Your code here
return couriersSolve 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