AnalystPath

Bake-Off Division Champions

PandasHardSenior level~10 min

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.

bakers
baker_iddivision
111
221
331
441
552
bakeoffs
bakeoff_idleft_bakerright_bakerleft_scoreright_score
1114430
2332212
3331120
4775552
5668811

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 bakers

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