LeetCode in Kotlin

2880. Select Data

Easy

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: 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 the name and age.

Solution

import pandas as pd

def selectData(students: pd.DataFrame) -> pd.DataFrame:
    return students[students.student_id == 101][['name','age']]
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy