Your question is Preprocess Data With Missing and Outliers. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Write a function to preprocess a complex dataset, including handling missing values and outliers.
Replace missing numeric values with the field median, then cap numeric values outside the 1.5 IQR range. Replace missing categorical values with the mode, breaking ties by choosing the lexicographically smallest value. Return a new list without modifying the input rows.
The input contains rows, a list of dictionaries, plus lists naming numeric and categorical fields. Every row contains each named field, and every field has at least one non-missing value. Return the processed list of dictionaries.
def preprocess_dataset(rows, numeric_fields, categorical_fields):