Lopsided Recipes
Problem
You are given a DataFrame `recipelines` loaded from `recipelines.csv`:
```text
+---------------+------+
| Column | Type |
+---------------+------+
| recipe_id | int |
| ingredient_id | int |
| grams | int |
+---------------+------+
(recipe_id, ingredient_id) is the primary key. Each row gives how many grams of one ingredient a recipe uses.
```
A recipe is **lopsided** when its single heaviest ingredient (its maximum grams) is strictly greater than the largest average-grams figure found among all recipes, where each recipe's average is taken over its own ingredients, and the comparison includes the recipe itself.
Return a DataFrame with one column `recipe_id` listing every lopsided recipe, in any order.
Input data
Example rows — the live problem includes the full dataset.
| recipe_id | ingredient_id | grams |
|---|---|---|
| 1 | 10 | 100 |
| 1 | 11 | 200 |
| 1 | 12 | 300 |
| 2 | 10 | 50 |
| 2 | 11 | 50 |
Expected output
Your answer should return 1 row with the columns recipe_id.
Starter code (Pandas (Python))
import pandas as pd
def lopsided_recipes(recipelines) -> pd.DataFrame:
# Your code here
return recipelinesSolve 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