AnalystPath

Class Attendance for Every Member and Class

PandasEasyJunior level~10 min

Problem

You are given three DataFrames.

`members` has columns `member_id` and `member_name`; one row per member.

`classes` has a single column `class_name`; one row per class.

`attendance` has columns `member_id` and `class_name`; there is no key and rows may repeat. Each row is one time a member showed up to a class. Every member is enrolled in every class.

Report, for every member and every class, how many times that member attended that class.

Return `member_id`, `member_name`, `class_name`, `times_attended`, ordered by `member_id` then `class_name`.

Input data

Example rows — the live problem includes the full dataset.

members
member_idmember_name
1Maya
2Dev
13Pia
6Otto
classes
class_name
Spin
Yoga
Boxing
attendance
member_idclass_name
1Spin
1Yoga
1Boxing
2Boxing
1Yoga

Expected output

Your answer should return 12 rows with the columns member_id, member_name, class_name, times_attended.

Starter code (Pandas (Python))

import pandas as pd

def class_attendance(members, classes, attendance) -> pd.DataFrame:
    # Your code here
    return members

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