mirror of https://github.com/doocs/leetcode.git
|
…
|
||
|---|---|---|
| .. | ||
| README.md | ||
| README_EN.md | ||
| Solution.py | ||
README_EN.md
| comments | difficulty | edit_url | tags | |
|---|---|---|---|---|
| true | Easy | https://github.com/doocs/leetcode/edit/main/solution/2800-2899/2883.Drop%20Missing%20Data/README_EN.md |
|
2883. Drop Missing Data
Description
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.
Solutions
Solution 1
Python3
import pandas as pd
def dropMissingData(students: pd.DataFrame) -> pd.DataFrame:
return students[students['name'].notnull()]