前言
如何判断pandas.DataFrame、Series是否包含缺失值NaN以及如何处理缺失值NaN。
Part.1
isnull() 函数
使用 isnull()、isna() 确定每个元素的缺失值 如果值为 NaN,则值为 True,如果不是,则值为 False。
读取数据集
panel_data = pd.read_csv("panel.bed", sep="\t")
panel_data:
Chrom Start End Gene Exon
0 chr1 115252169 115252369.0 NRAS NaN
1 chr1 115256380 115256619.0 NRAS NaN
2 chr1 11168333 NaN MTOR NaN
print(panel_data.isnull())
Chrom Start End Gene Exon
0 False False False False True
1 False False False False True
2 False False True False True
Part.2
all() 函数
配合isnull() 函数, 判断每一行/列的所有元素是否缺失值。
默认情况下为列