Find row which value in either one of the column is NaN

Viewed 17

Here is a dataframe that I am working with:

cl_id       a           c         d         e        A1              A2             A3
    0       1   -0.419279  0.843832 -0.530827    text76        1.537177      -0.271042
    1       2    0.581566  2.257544  0.440485    dafN_6        0.144228       2.362259
    2       3   -1.259333  1.074986  1.834653    system         NAN           1.100353
    3       4   -1.279785  0.272977  0.197011     Fifty       -0.031721       1.434273
    4       5    0.578348  0.595515  0.553483   channel        NaN               NaN
    5       6   -1.549588 -0.198588  0.373476     audio       -0.508501        NAN       

I would like to find rows that values in either column A2 or A3 is NaN. So it will return

cl_id       a           c         d         e        A1              A2             A3
    2       3   -1.259333  1.074986  1.834653    system         NAN           1.100353
    5       6   -1.549588 -0.198588  0.373476     audio       -0.508501        NAN   

Any help is appreciated.

1 Answers

You can do count

# 1 here is len(['A2', 'A3']) - count_na
count_na = 1
df[df[['A2','A3']].count(axis=1) == 1] 

Or you can check with isna and sum the result:

count_na = 1
df[df[['A2','A3']].isna().sum(axis=1) == count_na]
Related