8

I want to select rows which have multiple columns(4 in the following example) as null values. I have used the following code:

data[(data['relevent_experience'].isnull())&data['education_level'].isnull())&data['major_disciplne'].isnull())&data['relevent_experience'].isnull())]

This is a very complicated code. Is there a cleaner way to do the same thing?

Ronith
  • 169
  • 2
  • 5
  • 12
  • Use marked duplicate. Instead of `any` you can use `all`. – jpp Jul 13 '18 at 15:36
  • separate your statements in multiple row.s – Anton vBR Jul 13 '18 at 15:38
  • 4
    This is not a duplicate of the above mentioned question. I want to only those rows with null values in those specific columns. I don't care about other columns, but the above mentioned 4 columns should have null values. – Ronith Jul 13 '18 at 15:55
  • df_no_nan = df.dropna(subset=['Col1','Col2, 'Col3'], how='any') – P-S Nov 02 '18 at 16:31
  • check the accepted answer to this question https://stackoverflow.com/questions/36370839/better-way-to-drop-nan-rows-in-pandas – Ahmad Senousi Mar 30 '19 at 06:20
  • data[data.loc[:,'column1', 'column2',.., 'columnn'].isna().apply(lambda x: all(x), axis=1)] – krxat Jun 01 '20 at 17:31

0 Answers0