AnalystPath

Espresso Drinkers Who Skip Matcha

PandasEasyJunior level~10 min

Problem

DataFrame: `drink` (`drink.csv`)

```text
+-------------+--------+
| Column | Type |
+-------------+--------+
| drink_id | int |
| drink_name | object |
| price_cents | int |
+-------------+--------+
drink_id uniquely identifies each drink.
```

DataFrame: `ordering` (`ordering.csv`)

```text
+------------+----------+----------+------------+------+-------------+
| Column | Type |
+-------------+--------+
| barista_id | int |
| drink_id | int |
| guest_id | int |
| ordered_on | object |
| cups | int |
| total_cents | int |
+-------------+--------+
Each row records one order placed by a guest.
```

Write a function that returns the `guest_id` of every guest who has ordered an **Espresso** at least once but has **never** ordered a **Matcha**. Each qualifying guest should appear once.

Return the rows in any order.

**Example**

Input — `drink`:

```text
drink_id drink_name price_cents
1 Espresso 350
2 Latte 450
3 Matcha 500
```

Input — `ordering`:

```text
barista_id drink_id guest_id ordered_on cups total_cents
1 1 1 2021-01-21 2 700
1 2 2 2021-02-17 1 450
2 1 3 2021-06-02 1 350
3 3 3 2021-05-13 2 1000
```

Output:

```text
guest_id
1
```

Guest 1 ordered an Espresso and never a Matcha. Guest 3 ordered Espresso but also Matcha, so they are excluded; guest 2 never ordered Espresso.

Input data

Example rows — the live problem includes the full dataset.

drink
drink_iddrink_nameprice_cents
1Espresso350
2Latte450
3Matcha500
ordering
barista_iddrink_idguest_idordered_oncupstotal_cents
1112021-01-212700
1222021-02-171450
2132021-06-021350
3332021-05-1321000

Expected output

Your answer should return 1 row with the columns guest_id.

Starter code (Pandas (Python))

import pandas as pd

def espresso_not_matcha(drink: pd.DataFrame, ordering: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return ordering

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