AnalystPath

Coupon Redemption Rate

PandasEasyJunior level~10 min

Problem

DataFrame: `couponsent` (`couponsent.csv`)

```text
+------------+--------+
| Column | Type |
+------------+--------+
| store_id | int |
| shopper_id | int |
| sent_on | object |
+------------+--------+
```

DataFrame: `couponredeemed` (`couponredeemed.csv`)

```text
+-------------+--------+
| Column | Type |
+-------------+--------+
| store_id | int |
| shopper_id | int |
| redeemed_on | object |
+-------------+--------+
```

A coupon is identified by the `(store_id, shopper_id)` pair. The same pair may appear more than once in either DataFrame.

Report the overall **redemption rate**: the number of distinct `(store_id, shopper_id)` pairs that were redeemed divided by the number of distinct `(store_id, shopper_id)` pairs that were sent, rounded to 2 decimal places. Return a single column named `redeem_rate`. If no coupons were ever sent, the rate is `0.00`.

Input data

Example rows — the live problem includes the full dataset.

couponsent
store_idshopper_idsent_on
1102023-03-01
1112023-03-01
1122023-03-01
2102023-03-02
2132023-03-09
couponredeemed
store_idshopper_idredeemed_on
1102023-03-03
1112023-03-08
1112023-03-08
2132023-03-09
2132023-03-10

Expected output

Your answer should return 1 row with the columns redeem_rate.

Starter code (Pandas (Python))

import pandas as pd

def redemption_rate(couponsent: pd.DataFrame, couponredeemed: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return couponsent

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