AnalystPath

Scouts Who Earned Every Badge

PandasMediumMid level~10 min

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.

earned
scout_idbadge_code
150
260
350
360
160
badge
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 earned

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