Class Attendance for Every Member and Class
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.
| member_id | member_name |
|---|---|
| 1 | Maya |
| 2 | Dev |
| 13 | Pia |
| 6 | Otto |
| class_name |
|---|
| Spin |
| Yoga |
| Boxing |
| member_id | class_name |
|---|---|
| 1 | Spin |
| 1 | Yoga |
| 1 | Boxing |
| 2 | Boxing |
| 1 | Yoga |
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 membersSolve 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