Total Pages Read per Library Member
Problem
You are given two DataFrames. `members` (from `members.csv`) has columns `member_id` (the primary key) and `full_name`. `loans` (from `loans.csv`) has columns `loan_id` (the primary key), `member_id`, and `pages_read`; each row records how many pages a member read from one borrowed book.
Report the total pages read by every member. A member with no loans must still appear with a total of 0. Output `member_id`, `full_name`, and the total in a column named `pages read`. Order by `member_id`.
Input data
Example rows — the live problem includes the full dataset.
| member_id | full_name |
|---|---|
| 3 | Priya Nair |
| 7 | Diego Alves |
| 12 | Hannah Berg |
| 20 | Omar Said |
| loan_id | member_id | pages_read |
|---|---|---|
| 1 | 3 | 120 |
| 2 | 3 | 80 |
| 3 | 7 | 300 |
| 4 | 12 | 45 |
| 5 | 12 | 60 |
Expected output
Your answer should return 4 rows with the columns member_id, full_name, pages read.
Starter code (Pandas (Python))
import pandas as pd
def total_pages_per_member(members, loans) -> 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