comments | difficulty | edit_url |
---|---|---|
true |
简单 |
DataFrame students +-------------+--------+ | Column Name | Type | +-------------+--------+ | student_id | int | | name | object | | age | int | +-------------+--------+
在 name
列里有一些具有缺失值的行。
编写一个解决方案,删除具有缺失值的行。
返回结果格式如下示例所示。
示例 1:
输入: +------------+---------+-----+ | student_id | name | age | +------------+---------+-----+ | 32 | Piper | 5 | | 217 | None | 19 | | 779 | Georgia | 20 | | 849 | Willow | 14 | +------------+---------+-----+ 输出: +------------+---------+-----+ | student_id | name | age | +------------+---------+-----+ | 32 | Piper | 5 | | 779 | Georgia | 20 | | 849 | Willow | 14 | +------------+---------+-----+ 解释: 学号为 217 的学生所在行在 name 列中有空值,因此这一行将被删除。
import pandas as pd
def dropMissingData(students: pd.DataFrame) -> pd.DataFrame:
return students[students['name'].notnull()]