Was the Second Supply a Preferred Vendor?
Problem
You are given three DataFrames. `contractors` (from `contractors.csv`) has `contractor_id` (the key), `onboarded_day` and `preferred_vendor`. `supplies` (from `supplies.csv`) has `supply_id` (the key), `supplied_day`, `material_id` and `contractor_id` — the contractor who supplied the material (assume each contractor's supply dates are distinct). `materials` (from `materials.csv`) has `material_id` (the key) and `vendor`.
For each contractor, determine whether the **vendor of the second material they supplied (ordered by supply date)** equals their `preferred_vendor`. If the contractor supplied fewer than two materials, report `'no'`. Return `contractor_id` and a column named `second_supply_preferred` holding `'yes'` or `'no'`.
Example: contractor 1 prefers Acme; their second supply (material 200) is from Acme -> yes. Contractor 2 prefers Globex but supplied only one material -> no.
Input data
Example rows — the live problem includes the full dataset.
| contractor_id | onboarded_day | preferred_vendor |
|---|---|---|
| 1 | 2023-01-01 | Acme |
| 2 | 2023-01-01 | Globex |
| supply_id | supplied_day | material_id | contractor_id |
|---|---|---|---|
| 10 | 2023-02-01 | 100 | 1 |
| 11 | 2023-02-05 | 200 | 1 |
| 12 | 2023-03-01 | 300 | 2 |
| material_id | vendor |
|---|---|
| 100 | Globex |
| 200 | Acme |
| 300 | Globex |
Expected output
Your answer should return 2 rows with the columns contractor_id, second_supply_preferred.
Starter code (Pandas (Python))
import pandas as pd
def second_supply_check(contractors, supplies, materials) -> pd.DataFrame:
# Your code here
return contractorsSolve 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