AnalystPath

Popular Titles Borrowed in a Month

PandasEasyJunior level~10 min

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
title_idtitle_nameshelf
1Atlas of TidesA1
2Quiet EnginesB3
loan
title_idloaned_oncopies
12020-08-0360
12020-08-2050
22020-08-0940
22020-07-3190

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 title

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