本文整理了数据中空值的处理操作,主要内容如下:
为了便于描述,定义本文示例数据为如下结构:
df = pd.DataFrame([[1, np.nan], [np.nan, 4], [5,6],[np.nan,7]],columns=["A","B"])
df #定义示例数据df
判断数据中是否有空值
pandas isnull()函数
df.isnull() #返回df中各元素是否为空的同df大小的数据框
df["A"].isnull() #判断A列中空值情况
df[["A","B"]].isnull() # 指定多列进行空值判断,对于本文实例,下述代码效果同df.isnull()
pandas notnull()函数
df.notnull() #判断df中各元素是否 不是 空值
df["A"].isnull() #判断A列中非空值情况
df[["A","B"]].isnull() # 指定多列进行非空值判断,对于本文实例,下述代码效果同df.notnull()
numpy np.isnan() 函数
np.isnan(df) #