Problem
DataFrame students +————-+——–+ | Column Name | Type | +————-+——–+ | student_id | int | | name | object | | age | int | +————-+——–+
Write a solution to select the name and age of the student with student_id = 101
.
The result format is in the following example.
**Example 1:
|
|
Solution
Method 1 - Simple Filtering
Intuition
We need to select the name and age of the student with a specific student_id. This is a simple filter operation.
Approach
- Filter the DataFrame (or table) for rows where student_id = 101.
- Select only the name and age columns.
Code
|
|
|
|
|
|
Complexity
- ⏰ Time complexity:
O(N)
where N = number of students - 🧺 Space complexity:
O(1)
(output is a single row)