AnalystPath

Distinction Apprentices

PandasHardSenior level~10 min

Problem

An apprenticeship scheme records data in three DataFrames:
- `apprentices` with columns `apprentice_id`, `full_name`, `trade`.
- `units` with columns `unit_id`, `title`, `weeks`, `trade`, `core` (where `core` is 'Yes' or 'No').
- `records` with columns `apprentice_id`, `unit_id`, `cohort`, `mark`, `score`.

An apprentice earns a distinction when they meet ALL of these conditions within their own trade:
- they took every core unit of their trade and scored mark 'A' in each;
- they took at least two optional (non-core) units of their trade and scored at least 'B' (i.e. 'A' or 'B') in each of those optional units they took;
- their overall average `score` across all their records is at least 2.5.

Return a single column `apprentice_id`, ordered ascending.

Input data

Example rows — the live problem includes the full dataset.

apprentices
apprentice_idfull_nametrade
1NadiaPlumbing
2OmarPlumbing
3PriyaWelding
4QuinnWelding
units
unit_idtitleweekstradecore
101Pipe Fitting3PlumbingYes
102Drainage3PlumbingYes
103Arc Basics4WeldingYes
104Joint Prep4WeldingYes
105Green Plumbing3PlumbingNo
records
apprentice_idunit_idcohortmarkscore
11012024 IntakeA4.0
11022024 IntakeA4.0
11052024 IntakeA4.0
11072024 IntakeB3.5
21012024 IntakeA4.0

Expected output

Your answer should return 2 rows with the columns apprentice_id.

Starter code (Pandas (Python))

import pandas as pd

def distinction_apprentices(apprentices, units, records) -> pd.DataFrame:
    # Your code here
    return apprentices

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