AnalystPath

Book Suggestions from Reading Buddies

PandasMediumMid level~10 min

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.

buddies
reader_areader_b
12
13
14
23
24
reads
reader_idbook_id
188
223
324
456
511

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 buddies

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