计算数据框中具有1个或多个NaN的行 [英] Count rows with 1 or more NaNs in a Dataframe

查看:85
本文介绍了计算数据框中具有1个或多个NaN的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容:

print(df.isna().sum())

哪个给我:

city                 2
country              0
testid               0
house             1807
house_number       248
po_box            1845
zipcode            260
road               132
state                1
state_district    1817
suburb            1800
unit              1806

我想要列city, state, zip, and house

谢谢您的建议.

推荐答案

这就是我使用isnasum的方式:

This is how I would use isna and sum:

cols = ['city', 'state', 'zip', 'house']
df[df[cols].isna().sum(axis=1) > 0]


另一种选择是调用dropna并检查长度.


Another option is calling dropna and checking the length.

u = df.dropna(subset=['city', 'state', 'zip', 'house'])
len(df) - len(u)

这篇关于计算数据框中具有1个或多个NaN的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆