Quietly Rented Board Games
Problem
A board game cafe lends out games and tracks every rental.
DataFrame: `game` (`game.csv`)
```text
+-------------+--------+
| Column | Type |
+-------------+--------+
| game_id | int |
| title | object |
| shelved_on | object |
+-------------+--------+
```
`game_id` is unique. `shelved_on` is the date the game first became available to rent.
DataFrame: `rental` (`rental.csv`)
```text
+-------------+--------+
| Column | Type |
+-------------+--------+
| rental_id | int |
| game_id | int |
| copies | int |
| rented_on | object |
+-------------+--------+
```
`rental_id` is unique. Each row records that some copies of a game were rented on a date.
Write a function that returns the games rented fewer than 10 copies in the last year, excluding any game on the shelf for less than one month. Assume today is 2023-06-23, so 'last year' means rentals on or after 2022-06-23, and a game is too new if it was shelved on or after 2023-05-23. Return columns `game_id` and `title` in any order.
Input data
Example rows — the live problem includes the full dataset.
| game_id | title | shelved_on |
|---|---|---|
| 1 | Catacomb Quest | 2014-01-01 |
| 2 | River Trade | 2016-05-12 |
| 3 | Skyline Rails | 2023-06-10 |
| 4 | Meadow Keepers | 2023-06-01 |
| 5 | Tidepool | 2008-09-21 |
| rental_id | game_id | copies | rented_on |
|---|---|---|---|
| 1 | 1 | 2 | 2022-07-26 |
| 2 | 1 | 1 | 2022-11-05 |
| 3 | 3 | 8 | 2023-06-11 |
| 4 | 4 | 6 | 2023-06-05 |
| 5 | 4 | 5 | 2023-06-20 |
Expected output
Your answer should return 3 rows with the columns game_id, title.
Starter code (Pandas (Python))
import pandas as pd
def quiet_games(game: pd.DataFrame, rental: pd.DataFrame) -> pd.DataFrame:
# Your code here
return gameSolve 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