Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Preprocessing for Model Ingestion
00:00
5 left

Preprocessing for Model Ingestion

HardPython

Problem

Implement a preprocessing function for the Randstad Digital Belgium model-ingestion pipeline. Given raw records, convert selected numeric and categorical features into deterministic numeric vectors suitable for model input.

For numeric columns, replace None with the column median, then apply min-max normalization. If a column has the same value for every record, its normalized value must be 0.0. For categorical columns, replace None with the string "UNKNOWN", discover categories from the input batch, sort them lexicographically, and one-hot encode each value.

Return one vector per input record. Each vector must contain normalized numeric values first, followed by one-hot values for each categorical column in the order supplied by categorical_columns. Do not mutate the input records.

Formal Specification

  • rows is a non-empty list of dictionaries whose values are numbers, strings, or None.
  • numeric_columns and categorical_columns are lists of column names with no duplicates.
  • Every numeric column has at least one non-None value.
  • Return a list of lists containing only float values.
  • Median for an even number of values is the arithmetic mean of the two middle values.

Constraints

  • 1 <= len(rows) <= 10^4
  • 0 <= len(numeric_columns), len(categorical_columns) <= 50
  • The combined feature count is at most 500
  • Every numeric column has at least one non-None value
  • Column names within each column list are unique

Function Signature

def preprocess_dataset(rows, numeric_columns, categorical_columns):
Interviewer

Your question is Preprocessing for Model Ingestion. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.