Course of Each Learner's First Enrollment
Problem
An online learning platform logs each course a learner enrolled in, and when.
DataFrame: `enrollments` (from `enrollments.csv`)
| Column | Type |
|---------------|--------|
| learner_id | int |
| course_id | int |
| enroll_date | object |
| hours_studied | int |
Write a function that reports, for each learner, the `course_id` they enrolled in on their **earliest** `enroll_date`. Return columns `learner_id` and `course_id`, in any order.
Input data
Example rows — the live problem includes the full dataset.
| learner_id | course_id | enroll_date | hours_studied |
|---|---|---|---|
| 1 | 20 | 2023-01-05 | 5 |
| 1 | 21 | 2023-03-02 | 6 |
| 2 | 30 | 2023-02-18 | 1 |
| 3 | 11 | 2023-01-09 | 0 |
| 3 | 44 | 2023-06-07 | 5 |
Expected output
Your answer should return 3 rows with the columns learner_id, course_id.
Starter code (Pandas (Python))
import pandas as pd
def first_course(enrollments: pd.DataFrame) -> pd.DataFrame:
# Your code here
return enrollmentsSolve 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