Eligible Trade-In Payouts
Problem
DataFrame: `tradein` (`tradein.csv`)
```text
+----------+--------+--------+-------+-------+
| Column | Type | | | |
+----------+--------+--------+-------+-------+
| trade_id | int | | | |
| base_val | float | | | |
| payout | float | | | |
| east | float | | | |
| north | float | | | |
+----------+--------+--------+-------+-------+
trade_id uniquely identifies each trade-in. base_val is the appraised base value, payout is the offered payout, and (east, north) is the grid location of the drop-off depot (never missing).
```
Report the sum of `payout` over all trade-ins that satisfy **both** conditions:
- their `base_val` equals the `base_val` of at least one other trade-in, **and**
- their depot location `(east, north)` is unique — no other trade-in shares the same `(east, north)` pair.
Round the total to **two decimal places** and return it as a single column named `payout`. If no trade-in qualifies, return one row whose `payout` is `null`.
Input data
Example rows — the live problem includes the full dataset.
| trade_id | base_val | payout | east | north |
|---|---|---|---|---|
| 1 | 10 | 5 | 10 | 10 |
| 2 | 20 | 20 | 20 | 20 |
| 3 | 10 | 30 | 20 | 20 |
| 4 | 10 | 40 | 40 | 40 |
Expected output
Your answer should return 1 row with the columns payout.
Starter code (Pandas (Python))
import pandas as pd
def eligible_payout(tradein: pd.DataFrame) -> pd.DataFrame:
# Your code here
return tradeinSolve 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