-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2883-DropMissingData.py
More file actions
52 lines (46 loc) · 1.48 KB
/
2883-DropMissingData.py
File metadata and controls
52 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 2883. Drop Missing Data
# 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.
import pandas as pd
def dropMissingData(students: pd.DataFrame) -> pd.DataFrame:
#return students[students["name"] != None]
#return students.dropna(subset='name',how='any',axis=0)
students.dropna(subset=['name'], inplace=True)
return students
if __name__ == "__main__":
l = [
[101, 1, 15],
[101, 2, 11],
[103, None, 11],
[104, 4, 20]
]
print(dropMissingData(pd.DataFrame(l,columns=["email","name","age"])))