代码之家  ›  专栏  ›  技术社区  ›  Mendelsohn

函数来迭代pandas数据帧中的每一列

  •  0
  • Mendelsohn  · 技术社区  · 7 年前

    def count_nulls(df, col_name):
    col = df[col_name]
    bool_col = pd.isna(col)
    total_nulls = pd.Series.sum(bool_col)
    total_rows = len(col)
    pct_null = round((total_nulls / total_rows) * 100,2)
    print("The","\'"+ str(col_name) + "\'", "field has", str(total_nulls), "nulls which account for",
          str(pct_null) + "% of all values")
    

    ****图像****

    enter image description here

    0 回复  |  直到 7 年前
    推荐文章