AnalystPath

Captain of the Biggest Squad

PandasMediumMid level~10 min

Problem

You are given a DataFrame `roster` with columns `player_id`, `player_name`, `squad_id`, and `role`. `player_id` is unique. Each row is a player belonging to a squad, with a `role` such as 'Captain' or 'Member'. Every squad has exactly one captain.

Find the captain of the squad with the most players. If two or more squads tie for the largest size, return the captain of each of them. Return `captain_name` and `squad_id`, ordered by `squad_id`.

Input data

Example rows — the live problem includes the full dataset.

roster
player_idplayer_namesquad_idrole
1Ravi10Captain
2Mei10Member
3Tomas10Member
4Aisha20Captain
5Bode20Member

Expected output

Your answer should return 1 row with the columns captain_name, squad_id.

Starter code (Pandas (Python))

import pandas as pd

def captain_of_the_biggest_squad(roster) -> pd.DataFrame:
    # Your code here
    return roster

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