Home > Net >  Convert a lambda function to a regular function
Convert a lambda function to a regular function

Time:11-24

I'm trying to understand how can I convert a lambda function to a normal one. I have this lambda function that it supposed to fill the null values of each column with the mode

def fill_nn(data):
    df= data.apply(lambda column: column.fillna(column.mode()[0]))
    return df

I tried this:

def fill_nn(df):
    for column in df:
        if df[column].isnull().any():
            return df[column].fillna(df[column].mode()[0])

CodePudding user response:

Hi

  • Related