Scouts Who Earned Every Badge
Problem
You are given two DataFrames. `earned` has columns `scout_id` and `badge_code` and may contain duplicate rows. `badge` has a single column `badge_code` listing every badge that exists.
Return the `scout_id` of each scout who has earned **all** of the badges in `badge`. Output one column, `scout_id`. Duplicate (scout_id, badge_code) rows must not let a scout look like they earned more distinct badges than they really did.
Input data
Example rows — the live problem includes the full dataset.
| scout_id | badge_code |
|---|---|
| 1 | 50 |
| 2 | 60 |
| 3 | 50 |
| 3 | 60 |
| 1 | 60 |
| badge_code |
|---|
| 50 |
| 60 |
Expected output
Your answer should return 2 rows with the columns scout_id.
Starter code (Pandas (Python))
import pandas as pd
def scouts_who_earned_every_badge(earned, badge) -> pd.DataFrame:
# Your code here
return earnedSolve 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