Search code examples
pythonanalytics

How to count the column name that having missing


I have a large datasets. I partitioned the data into training and test.

I found the missing values of the independent variable.

enter image description here

I want to calculate the number of columns that have the missing value. in this case, I should get 12 names. I was only able to sum the whole column

Here is my attempt:

finding_missing_values = data.train.isnull().sum()
finding_missing_values

finding_missing_values.sum()

is there a way I can count the number of column that has a missing value?


Solution

  • Take data list to and then count non zero values as follows.

    finding_missing_values = (data.train.isnull().sum()).to_list()
    number of missing value columns = sum(k>0 for k in finding_missing_values )
    print(number of missing value columns)
    

    should Give #

    12