-3

I am facing a issue with null rows. I want only the null rows of only certain columns of a data frame. Is it possible to get the null rows?

In [57]: df
Out[57]: 
   a   b   c  d  e
0  0   1   2  3  4
1  0 NaN   0  1  5
2  0   0 NaN  NaN 5
3  0   1   2   5  Nan
4  0   1   2   6  Nan

Now I want nulls in b,c,e the result should be this one:

Out[57]: 
   a   b   c  d  e
1  0 NaN   0  1  5
2  0   0 NaN  NaN 5
3  0   1   2   5  Nan
4  0   1   2   6  Nan
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
Ram dr
  • 111
  • 5

1 Answers1

2

You could use isna() for axis=1.

df = pd.DataFrame({"a":[0,0,0,0,0], "b":[1,np.NaN,0,1,1], "c":[2,0,np.NaN,2,2], "d":[3,1,np.NaN,5,6], "e":[4,5,5,np.NaN,np.NaN]})

>>> df[df.isna().any(axis=1)]
   a    b    c    d    e
1  0  NaN  0.0  1.0  5.0
2  0  0.0  NaN  NaN  5.0
3  0  1.0  2.0  5.0  NaN
4  0  1.0  2.0  6.0  NaN

The same could be done using isnull() function

df[df.isnull().any(axis=1)]