Skip to content

Latest commit

 

History

History
85 lines (61 loc) · 1.75 KB

File metadata and controls

85 lines (61 loc) · 1.75 KB
comments difficulty edit_url tags
true
简单
Pandas

English Version

题目描述

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 列中有空值,因此这一行将被删除。

解法

方法一

Python3

import pandas as pd


def dropMissingData(students: pd.DataFrame) -> pd.DataFrame:
    return students[students['name'].notnull()]