Enrollments in Missing Courses
Problem
You are given two DataFrames. `course` has columns `course_id` and `label`, one row per course offered by the academy (`course_id` is unique). `enrollment` has columns `enroll_id`, `learner`, and `course_id` (`enroll_id` is unique). A `course_id` should reference a real course, but because of a data-entry bug some enrollments point at a `course_id` that does not exist in `course`.
Report every enrollment whose `course_id` does **not** appear in `course`. Return `enroll_id` and `learner`. Rows may be in any order.
**Example**
```text
course:
+-----------+---------+
| course_id | label |
+-----------+---------+
| 1 | Algebra |
| 2 | Optics |
+-----------+---------+
enrollment:
+-----------+---------+-----------+
| enroll_id | learner | course_id |
+-----------+---------+-----------+
| 100 | Priya | 1 |
| 101 | Marcus | 9 |
| 102 | Lena | 2 |
+-----------+---------+-----------+
Result:
+-----------+---------+
| enroll_id | learner |
+-----------+---------+
| 101 | Marcus |
+-----------+---------+
```
Enrollment 101 points at course 9, which has no matching row in course, so it is the only invalid enrollment.
Input data
Example rows — the live problem includes the full dataset.
| course_id | label |
|---|---|
| 1 | Algebra |
| 2 | Optics |
| enroll_id | learner | course_id |
|---|---|---|
| 100 | Priya | 1 |
| 101 | Marcus | 9 |
| 102 | Lena | 2 |
Expected output
Your answer should return 1 row with the columns enroll_id, learner.
Starter code (Pandas (Python))
import pandas as pd
def enrollments_in_missing_courses(course, enrollment) -> pd.DataFrame:
# Your code here
return enrollmentSolve 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