简体   繁体   English

计算Dataframe中具有1个或多个NaN的行

[英]Count rows with 1 or more NaNs in a Dataframe

I have the following: 我有以下内容:

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

Which gives me: 这给了我:

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

I want the total number of rows that have 1 or more NaN values from columns city, state, zip, and house 我想从列city, state, zip, and house中获得具有1个或多个NaN值的总行数

Thanks for any suggestions. 谢谢你的任何建议。

This is how I would use isna and sum : 这是我如何使用isnasum

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

Another option is calling dropna and checking the length. 另一种选择是调用dropna并检查长度。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM