Bake-Off Division Champions
Problem
You are given two DataFrames. `bakers` (from `bakers.csv`) has columns `baker_id` and `division`; each baker competes in exactly one division. `bakeoffs` (from `bakeoffs.csv`) has columns `bakeoff_id`, `left_baker`, `right_baker`, `left_score`, `right_score`; each row is one head-to-head bake-off between two bakers and the score each earned in it.
Sum every baker's total score across all bake-offs they appeared in (a baker with no bake-offs has a total of 0). For each division, return the champion: the baker with the highest total score, breaking ties by the smaller `baker_id`. Output columns: `division`, `baker_id`.
Input data
Example rows — the live problem includes the full dataset.
| baker_id | division |
|---|---|
| 11 | 1 |
| 22 | 1 |
| 33 | 1 |
| 44 | 1 |
| 55 | 2 |
| bakeoff_id | left_baker | right_baker | left_score | right_score |
|---|---|---|---|---|
| 1 | 11 | 44 | 3 | 0 |
| 2 | 33 | 22 | 1 | 2 |
| 3 | 33 | 11 | 2 | 0 |
| 4 | 77 | 55 | 5 | 2 |
| 5 | 66 | 88 | 1 | 1 |
Expected output
Your answer should return 3 rows with the columns division, baker_id.
Starter code (Pandas (Python))
import pandas as pd
def division_champions(bakers, bakeoffs) -> pd.DataFrame:
# Your code here
return bakersSolve 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