stephen carvalho
stephen carvalho

Reputation: 157

How to print the name of the column with missing values and the count of missing values in Python?

I tried this

print(housing.columns[housing.isnull().any()], housing.isnull().sum().sum())

and Got the following output:

Index(['total_bedrooms'], dtype='object') 207

But I'm trying to get the following output:

(total_bedrooms, 207 )

I believe there's a more intuitive way to get the answer I want than the way I did. Any help would be appreciated.

Upvotes: 1

Views: 90

Answers (1)

BENY
BENY

Reputation: 323356

We can do in one line

[*df.isnull().sum().loc[lambda x : x>0].items()]

Upvotes: 1

Related Questions