Recipe Suggestions From Connections
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.
| member_a | member_b |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 2 | 3 |
| 2 | 4 |
| member_id | recipe_id |
|---|---|
| 1 | 88 |
| 2 | 23 |
| 3 | 24 |
| 4 | 56 |
| 5 | 11 |
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 connectionsSolve 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