1.1NaN in Series
s1 = pd.Series([1,2,np.nan,3,4],index=["a","b","c","d","e"])
1 s1.isnull()# s1.notnull() 返回bool 2 a False 3 b False 4 c True 5 d False 6 e False 7 dtype: bool
删除nan
1 s1.dropna()#去掉nan的项 2 a 1.0 3 b 2.0 4 d 3.0 5 e 4.0 6 dtype: float64
1.2 NaN in DataFrame
df.isnull() 生成所有数据的true/false矩阵
df.isnull().any()
则会判断哪些”列”存在缺失值
df.isnull().all() 只有在那一列全为NAN时才会返回True
df.notnull()同理
df.dropna(axis=0, how=‘any‘, thresh=None, subset=None, inplace=False)
df.fillna(value=None, method=None, axis=None, inplace=False, limit=None, downcast=None, **kwargs)