Select Data - Problem

You are given a DataFrame called students with the following structure:

Column NameType
student_idint
nameobject
ageint

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
Select Data: Filter student_id = 101, return name and ageInput DataFrame100Alice20101Bob22102Charlie19student_idnameageFilter & SelectOutput ResultBob22nameagestudents[students['student_id'] == 101][['name', 'age']]Result: [{"name": "Bob", "age": 22}]
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
Asked in
Google 25 Amazon 20 Microsoft 15 Netflix 10
23.0K Views
High Frequency
~5 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen