How to select rows with one or more nulls from a pandas DataFrame without listing columns explicitly?

I have a dataframe with ~300K rows and ~40 columns.
I want to find out if any rows contain null values – and put these ‘null’-rows into a separate dataframe so that I could explore them easily.

I can create a mask explicitly:

mask = False
for col in df.columns: 
    mask = mask | df[col].isnull()
dfnulls = df[mask]

Or I can do something like:

df.ix[df.index[(df.T == np.nan).sum() > 1]]

Is there a more elegant way of doing it (locating rows with nulls in them)?

6 Answers
6

Leave a Comment