一、缺失值

1.空值判断

isnull()空值为True,非空值为False

notnull() 空值为False,非空值为True

s = pd.Series([1,2,'3',np.nan,'hello',np.nan])
df = pd.DataFrame({'a':[1,2,np.nan,'3'],'b':[2,np.nan,'3','hello']})
print(s.isnull())
print(s[s.isnull() == False])  #求s中的非空值,或者直接s[s.notnull()]

print(df.notnull())
print(df[df['b'].notnull()])  #求s中的非空值,或者df[df.isnull() == False]
0    False
1    False
2    False
3     True
4    False
5     True
dtype: bool
0        1
1        2
2        3
4    hello
dtype: object
       a      b
0   True   True
1   True  False
2  False   True
3   True   True
     a      b
0    1      2
2  NaN      3
3    3  hello
结果

相关文章: