Distinction Apprentices
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.
| apprentice_id | full_name | trade |
|---|---|---|
| 1 | Nadia | Plumbing |
| 2 | Omar | Plumbing |
| 3 | Priya | Welding |
| 4 | Quinn | Welding |
| unit_id | title | weeks | trade | core |
|---|---|---|---|---|
| 101 | Pipe Fitting | 3 | Plumbing | Yes |
| 102 | Drainage | 3 | Plumbing | Yes |
| 103 | Arc Basics | 4 | Welding | Yes |
| 104 | Joint Prep | 4 | Welding | Yes |
| 105 | Green Plumbing | 3 | Plumbing | No |
| apprentice_id | unit_id | cohort | mark | score |
|---|---|---|---|---|
| 1 | 101 | 2024 Intake | A | 4.0 |
| 1 | 102 | 2024 Intake | A | 4.0 |
| 1 | 105 | 2024 Intake | A | 4.0 |
| 1 | 107 | 2024 Intake | B | 3.5 |
| 2 | 101 | 2024 Intake | A | 4.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 apprenticesSolve 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