Filling every missing value with the global mean ignores structure: a missing house price in London shouldn't be filled with the national average.
Implement impute(df, col, by, strategy="median"):
col with the strategy ("median" or "mean") of the row's group (by is a column name or list of names).f"{col}_was_missing" so the model can still see which values were imputed.Then implement missing_report(df): a DataFrame indexed by column name with n_missing and pct_missing (0–100, rounded to 1 decimal), sorted by n_missing descending, then column name, including only columns with missing values.