1

we all know the famous question: How to drop rows of Pandas DataFrame whose value in a certain column is NaN

But how can I select the rows in a pandas dataframe df, where at least one column is NaN. So that:

df
   columnA columnB
0   NaN        1
1   1          2
2   NaN       NaN
3   1         NaN

will lead to:

df
   columnA columnB
0   NaN        1
2   NaN       NaN
3   1         NaN
PV8
  • 5,799
  • 7
  • 43
  • 87

1 Answers1

5

Use isnull with any

df[df.isnull().any(1)]
Out[122]: 
   columnA  columnB
0      NaN      1.0
2      NaN      NaN
3      1.0      NaN
BENY
  • 317,841
  • 20
  • 164
  • 234