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

Python Pandas Replace Nan values with mean or mode

Typology: Quizzes

2022/2023

Uploaded on 04/16/2023

mudassir84
mudassir84 🇵🇰

1 document

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1

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