AnalystPath

Total Pages Read per Library Member

PandasEasyJunior level~10 min

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.

members
member_idfull_name
3Priya Nair
7Diego Alves
12Hannah Berg
20Omar Said
loans
loan_idmember_idpages_read
13120
2380
37300
41245
51260

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 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