Book Suggestions from Reading Buddies
Problem
You are given two DataFrames.
`buddies` has columns `reader_a` and `reader_b`. Each row means `reader_a` and `reader_b` are reading buddies. The relationship is mutual but is stored once, in either order of the two ids.
`reads` has columns `reader_id` and `book_id`. Each row means `reader_id` has read `book_id`.
Suggest books to **reader 1** based on what their reading buddies have read. Do not suggest a book reader 1 has already read. Return each suggested book once.
Return the single column `suggested_book` with no duplicates, in any order.
Input data
Example rows — the live problem includes the full dataset.
| reader_a | reader_b |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 2 | 3 |
| 2 | 4 |
| reader_id | book_id |
|---|---|
| 1 | 88 |
| 2 | 23 |
| 3 | 24 |
| 4 | 56 |
| 5 | 11 |
Expected output
Your answer should return 5 rows with the columns suggested_book.
Starter code (Pandas (Python))
import pandas as pd
def book_suggestions(buddies, reads) -> pd.DataFrame:
# Your code here
return buddiesSolve 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