Popular Titles Borrowed in a Month
Problem
You are given two DataFrames. `title` has columns `title_id`, `title_name`, and `shelf`, one row per library title (`title_id` is unique). `loan` has columns `title_id`, `loaned_on`, and `copies`; it may contain several rows per title, each recording how many copies of a title were loaned out on a given day.
Find every title whose **total copies loaned during August 2020** is **at least 100**. Report `title_name` and the summed quantity under the column `copies`. Rows may be in any order.
**Example**
```text
title:
+----------+----------------+--------+
| title_id | title_name | shelf |
+----------+----------------+--------+
| 1 | Atlas of Tides | A1 |
| 2 | Quiet Engines | B3 |
+----------+----------------+--------+
loan:
+----------+------------+--------+
| title_id | loaned_on | copies |
+----------+------------+--------+
| 1 | 2020-08-03 | 60 |
| 1 | 2020-08-20 | 50 |
| 2 | 2020-08-09 | 40 |
| 2 | 2020-07-31 | 90 |
+----------+------------+--------+
Result:
+----------------+--------+
| title_name | copies |
+----------------+--------+
| Atlas of Tides | 110 |
+----------------+--------+
```
Atlas of Tides loaned 110 copies in August (>= 100). Quiet Engines only loaned 40 in August (its 90 fall in July), so it is excluded.
Input data
Example rows — the live problem includes the full dataset.
| title_id | title_name | shelf |
|---|---|---|
| 1 | Atlas of Tides | A1 |
| 2 | Quiet Engines | B3 |
| title_id | loaned_on | copies |
|---|---|---|
| 1 | 2020-08-03 | 60 |
| 1 | 2020-08-20 | 50 |
| 2 | 2020-08-09 | 40 |
| 2 | 2020-07-31 | 90 |
Expected output
Your answer should return 1 row with the columns title_name, copies.
Starter code (Pandas (Python))
import pandas as pd
def popular_titles_borrowed_in_a_month(title, loan) -> pd.DataFrame:
# Your code here
return titleSolve 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