Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Preprocess Data With Missing and Outliers

MediumPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Constraints

  • 1 <= len(rows) <= 10^4
  • Every named field exists in every row
  • Each numeric and categorical field has at least one non-missing value
  • Numeric values are integers or floating-point numbers
  • Categorical values are non-empty strings
  • Missing values are represented by null

Function Signature

def preprocess_dataset(rows, numeric_fields, categorical_fields):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output