AnalystPath

Member Count per Club

PandasMediumMid level~10 min

Problem

You are given two DataFrames.

`club`
```text
+-----------+-----------+
| Column | Type |
+-----------+-----------+
| club_id | int |
| club_name | object |
+-----------+-----------+
club_id is the unique key.
```

`member`
```text
+-------------+-----------+
| Column | Type |
+-------------+-----------+
| member_id | int |
| member_name | object |
| year_level | object |
| club_id | int |
+-------------+-----------+
```

Count how many members belong to each club, including clubs with **zero** members. Return columns `club_name`, `member_count`, ordered by `member_count` descending, breaking ties by `club_name` ascending.

Input data

Example rows — the live problem includes the full dataset.

member
member_idmember_nameyear_levelclub_id
10AyaY11
11BenY21
12ColeY12
club
club_idclub_name
1Chess
2Robotics
3Debate

Expected output

Your answer should return 3 rows with the columns club_name, member_count.

Starter code (Pandas (Python))

import pandas as pd

def members_per_club(member: pd.DataFrame, club: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return member

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