Docsity

Replace Nan values with mean or mode, Quizzes of Computer science

Partial preview of the text

Download Replace Nan values with mean or mode and more Quizzes Computer science in PDF only on Docsity!

def fill_missing(df): global PREDICTORS NUMERICAL, PREDICTORS_CATEGORICAL Bae dfr = df.copy() for c in PREDICTORS_NUMERICAL: value = dfr[c].mean() dfr[c].fillna(value , inplace = True) for d in PREDICTORS CATEGORICAL: value = dfr[d].mode().sort_values()[@] dfr[d].fillna(value, inplace = True) return dfr