AnalystPath

Recipe Suggestions From Connections

PandasHardSenior level~10 min

Problem

A cooking community lets members connect and save recipes.

DataFrame `connections` (from `connections.csv`):

```text
+----------+------+
| Column | Type |
+----------+------+
| member_a | int |
| member_b | int |
+----------+------+
(member_a, member_b) is the primary key. Each row means member_a and member_b are connected. Connections are mutual but each pair is stored only once (in one direction).
```

DataFrame `saves` (from `saves.csv`):

```text
+-----------+------+
| Column | Type |
+-----------+------+
| member_id | int |
| recipe_id | int |
+-----------+------+
(member_id, recipe_id) is the primary key. Each row means a member saved a recipe.
```

The app suggests a recipe to a member when at least one of that member's connections has saved it **and** the member has not already saved it themselves. For every member, report how many of their connections saved each suggested recipe.

Return a DataFrame with columns `member_id`, `recipe_id`, and `connection_saves` (the count of connections who saved it), in any order.

Input data

Example rows — the live problem includes the full dataset.

connections
member_amember_b
12
13
14
23
24
saves
member_idrecipe_id
188
223
324
456
511

Expected output

Your answer should return 16 rows with the columns member_id, recipe_id, connection_saves.

Starter code (Pandas (Python))

import pandas as pd

def recipe_suggestions_from_connections(connections, saves) -> pd.DataFrame:
    # Your code here
    return connections

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