【问题标题】:How to print the name of the column with missing values and the count of missing values in Python?如何在 Python 中打印具有缺失值的列的名称和缺失值的计数?
【发布时间】:2020-03-19 02:23:24
【问题描述】:

我试过了

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

得到以下输出:

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

但我正在尝试获得以下输出:

(total_bedrooms, 207 )

我相信有一种比我做的方式更直观的方式来获得我想要的答案。任何帮助将不胜感激。

【问题讨论】:

    标签: python python-3.x pandas jupyter-notebook data-science


    【解决方案1】:

    我们可以一行完成

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-08
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多