Replace zero in DataFrame



    Wyx Smrf


    The replace_zero() function replaces any zero value in the given dataframe column with the median value of the dataframe.

    Filename pattern: .ipynb, .py

    import pandas as pd
    def replace_zero(dataframe, column):
      median = dataframe[column].median()
      dataframe.replace(to_replace=0, value=median, inplace=True)
      return dataframe
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.