LeetCode in Kotlin

2883. Drop Missing Data

Easy

DataFrame students

+-------------+--------+ 
| Column Name | Type   | 
+-------------+--------+ 
| student_id | int    | 
| name        | object | 
| age         | int    | 
+-------------+--------+

There are some rows having missing values in the name column.

Write a solution to remove the rows with missing values.

The result format is in the following example.

Example 1:

Input:

+------------+---------+-----+ 
| student_id | name    | age | 
+------------+---------+-----+ 
| 32         | Piper   | 5   | 
| 217        | None    | 19  | 
| 779        | Georgia | 20  | 
| 849        | Willow  | 14  | 
+------------+---------+-----+

Output:

+------------+---------+-----+ 
| student_id | name    | age | 
+------------+---------+-----+ 
| 32         | Piper   | 5   | 
| 779        | Georgia | 20  | 
| 849        | Willow  | 14  | 
+------------+---------+-----+

Explanation: Student with id 217 havs empty value in the name column, so it will be removed.

Solution

import pandas as pd

def dropMissingData(students: pd.DataFrame) -> pd.DataFrame:
   r = pd.DataFrame(students)
   r.dropna(subset='name', inplace=True)
   return r
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