问题
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
Thanks for any suggestions.
回答1:
This is how I would use isna
and sum
:
cols = ['city', 'state', 'zip', 'house']
df[df[cols].isna().sum(axis=1) > 0]
Another option is calling dropna
and checking the length.
u = df.dropna(subset=['city', 'state', 'zip', 'house'])
len(df) - len(u)
来源:https://stackoverflow.com/questions/54205469/count-rows-with-1-or-more-nans-in-a-dataframe