def imputeMissing(df): column_list = df.columns.to_list() for col in column_list: sumOfMissing = df[col].isna().sum() if df[col].isna().any(): if df[col].dtype == "object": modeColumn = df[col].mode()[0] df[col] = df[col].fillna(modeColumn) print("There are ",sumOfMissing," missing values that need to fill for ",col) print("Imputing done with using mode value of ",col," that ",modeColumn) print("*"*60) else: meanColumn = df[col].mean() df[col] = df[col].fillna(meanColumn) meanAfter = df[col].mean() print("There are ",sumOfMissing," missing values that need to fill.") print("Imputing done with using mean value of ",col," that ",meanColumn) print("Mean before imputing : ", meanColumn) print("Mean after imputing : ", meanAfter) print("*"*60) else: print("There is no missing value for ",col,"!")