0

Say I have a dataset having 100 columns and 25 columns having one or more null values.

How can I get the total counts of columns as the output say something like out of 100 columns 25 columns have null values and 75 has no null values?

As the following code gives me an error:

data[data.columns[data.isnull() == True]].shape[1]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nisrin Dhoondia
  • 145
  • 1
  • 10

1 Answers1

1

You need to use any:

s = data.isnull().any()

# number of columns with null
num_col_with_null = s.sum()

# number without
df.shape[1] - num_col_with_null
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74