AnalystPath

Lopsided Recipes

PandasMediumMid level~10 min

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.

recipelines
recipe_idingredient_idgrams
110100
111200
112300
21050
21150

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 recipelines

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