I have a function that handles any null values for my machine learning project. I would like to know of a way to save a function and reuse it same way I can save a trained machine learning algorithm using pickle and use it on my deployed app backend.
Function to save
def handle_nulls(df):
df = df[df['account_status'].notna()]
df = df[df['probability'].notna()]
max = df['am_daysincelast_txn'].max()
df['am_daysincelast_txn'].fillna(max, inplace=True)
max = df['years_on_net'].max()
df['years_on_net'].fillna(max, inplace=True)
return df
df = handle_nulls(df)
My way pickel.dump(handle_null(), open('handle_null.pkl', 'wb'))
doesn't work