-
-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathpd_notnull().py
111 lines (77 loc) · 1.77 KB
/
pd_notnull().py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
"""
#Handling Missing Values in Pandas
* Tutorial: https://news.towardsai.net/hmv
* Github
"""
#Import Required Libraries:
import numpy as np
import pandas as pd
#Scalar arguments:
#Numerical value
pd.notnull(28)
#Scalar arguments:
#String value
pd.notnull("Pratik")
#Scalar arguments:
#Empty strings are not considered as null values
pd.notnull("")
#Scalar arguments:
#Infinite values are not considered as null values
pd.notnull(np.inf)
#Scalar arguments:
#NaN: Not a Number
pd.notnull(np.NaN)
#Scalar arguments:
#None
pd.notnull(None)
#Scalar arguments:
#NA: Not Available
pd.notnull(pd.NA)
#Scalar arguments:
#NaT: Not a Timestamp
pd.notnull(pd.NaT)
#nd-arrays:
arr = np.array([1,2,"Blue"])
print(arr)
print("\n")
pd.notnull(arr)
#nd-arrays:
#Empty strings are not considered as NA values
arr = np.array([[1,2,None],
[3,4,pd.NA],
[5,np.NaN,6],
["",7,8],
["Blue",pd.NaT,"Red"]])
print(arr)
print("\n")
pd.notnull(arr)
#For index values:
id = pd.Index([1,2,np.NaN,"Blue"])
print(id)
print("\n")
pd.notnull(id)
#For index values:
id = pd.DatetimeIndex([pd.Timestamp("2020-10-28"),
pd.Timestamp(""),
None,
np.NaN,
pd.NA,
pd.NaT])
print(id)
print("\n")
pd.notnull(id)
#Series:
s = pd.Series([1,2,3,None,4,np.NaN,pd.NA,pd.NaT,"Blue"])
print(s)
print("\n")
pd.notnull(s)
#DataFrame:
df = pd.DataFrame({"Name":["Alan","Berta","Charlie",None],
"Age":[32,45,np.NaN,28],
"Birthday":[pd.NaT,None,pd.Timestamp("1975-10-28"),np.NaN],
"Country":["USA","","USA","Canada"]
})
print(df)
print("\n")
pd.notnull(df)