2880. Select Data
DataFrame students
Column Name | Type |
---|---|
student_id | int |
name | object |
age | int |
Instructions
- 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
Input:
student_id | name | age |
---|---|---|
101 | Ulysses | 13 |
53 | William | 10 |
128 | Henry | 6 |
3 | Henry | 11 |
Output:
name | age |
---|---|
Ulysses | 13 |
Explanation:
Student Ulysses has
student_id = 101
, we select thename
andage
.
Submissions
python
import pandas as pd
def selectData(students: pd.DataFrame) -> pd.DataFrame:
return students.loc[students['student_id'] == 101, ['name', 'age']]
Explanation
Python (Pandas)
Submitted by @noeyislearning
import pandas as pd
: Import thepandas
library.def selectData(students: pd.DataFrame) -> pd.DataFrame:
: Define a function that takes a DataFramestudents
and returns a DataFrame.return students.loc[students['student_id'] == 101, ['name', 'age']]
: Select the rows wherestudent_id
is equal to 101 and columnsname
andage
.