Chefs Who Tasted Their Own Dish
Problem
You are given a DataFrame `tastings` loaded from `tastings.csv` with the columns `dish_id`, `chef_id`, `taster_id` and `taste_day`. There is no single-column key; each row means `taster_id` tasted dish `dish_id`, which was created by `chef_id`, on `taste_day`.
Find every chef who tasted at least one of their own dishes (the chef and the taster are the same person). Return one row per such chef in a single column named `id`, sorted by `id` in ascending order.
Example `tastings`:
```text
dish_id chef_id taster_id taste_day
1 5 5 2024-01-01
2 5 7 2024-01-01
3 8 8 2024-01-02
4 9 5 2024-01-03
```
Expected result is `[5, 8]`: chef 5 tasted dish 1 (their own) and chef 8 tasted dish 3 (their own).
Input data
Example rows — the live problem includes the full dataset.
| dish_id | chef_id | taster_id | taste_day |
|---|---|---|---|
| 1 | 5 | 5 | 2024-01-01 |
| 2 | 5 | 7 | 2024-01-01 |
| 3 | 8 | 8 | 2024-01-02 |
| 4 | 9 | 5 | 2024-01-03 |
Expected output
Your answer should return 2 rows with the columns id.
Starter code (Pandas (Python))
import pandas as pd
def self_tasting_chefs(tastings) -> pd.DataFrame:
# Your code here
return tastingsSolve 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