AnalystPath

Course of Each Learner's First Enrollment

PandasEasyJunior level~10 min

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.

enrollments
learner_idcourse_idenroll_datehours_studied
1202023-01-055
1212023-03-026
2302023-02-181
3112023-01-090
3442023-06-075

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 enrollments

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