Select Data - Problem
You are given a DataFrame called students with the following structure:
| 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 should be a DataFrame containing only the name and age columns for the matching student.
Input & Output
Example 1 — Basic Selection
$
Input:
students = [{"student_id": 100, "name": "Alice", "age": 20}, {"student_id": 101, "name": "Bob", "age": 22}, {"student_id": 102, "name": "Charlie", "age": 19}]
›
Output:
[{"name": "Bob", "age": 22}]
💡 Note:
Filter for student_id = 101 (Bob) and select only name and age columns
Example 2 — First Student Match
$
Input:
students = [{"student_id": 101, "name": "Diana", "age": 21}, {"student_id": 103, "name": "Eve", "age": 23}]
›
Output:
[{"name": "Diana", "age": 21}]
💡 Note:
Student 101 is Diana, so return her name and age
Example 3 — No Match Found
$
Input:
students = [{"student_id": 100, "name": "Alice", "age": 20}, {"student_id": 102, "name": "Charlie", "age": 19}]
›
Output:
[]
💡 Note:
No student with ID 101 exists, so return empty result
Constraints
- 1 ≤ students.length ≤ 1000
- student_id is unique for each student
- 1 ≤ age ≤ 100
- name is a non-empty string
Visualization
Tap to expand
Understanding the Visualization
1
Input DataFrame
Students table with student_id, name, age columns
2
Filter by ID
Find rows where student_id equals 101
3
Select Columns
Extract only name and age from matching rows
Key Takeaway
🎯 Key Insight: Use pandas boolean indexing to combine filtering and column selection in one elegant operation
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code