Data Cleaning Exercises

Interview questions

Missing values

Missing versus empty versus zero, imputation and leakage. Try answering out loud before opening the model answer.
  1. junior

    1. What's the difference between a missing value, an empty string and zero?

    What it tests: Precision about missingness.

    Model answer and scoring

    Missing means nothing was recorded. An empty string means something was recorded and it was empty. Zero is a measurement. They answer different questions, so I only convert between them when a rule says so, for example turning blank text into missing after trimming.

    Strong answers

    • Three distinct meanings with an example.

    Red flags

    • Treats them as interchangeable.

    Practise it: Label unknown categories, keep missing numbers missing

  2. mid

    2. When is it acceptable to fill missing values, and with what?

    What it tests: Judgement about imputation.

    Model answer and scoring

    For a category used for grouping, a visible label like "unknown" is fine. For measurements, filling creates fake observations; I prefer leaving them missing. If an analysis needs imputation, I fit the fill value on training data only and add a flag column marking imputed values.

    Strong answers

    • Distinguishes labels from measurements.
    • Mentions flags and fitting on training data.

    Red flags

    • Fills everything with 0 or the mean by default.

    Practise it: Fill gaps with a median learned from training data only

  3. senior

    3. Explain how filling missing values can leak information in a modelling project.

    What it tests: Train/test leakage.

    Model answer and scoring

    If the fill value, say a median, is computed on the whole dataset, the test rows influence the inputs the model is evaluated on, so test performance is optimistic. The fill must be fitted on training data and applied unchanged to test and future data.

    Strong answers

    • Fit on train, apply to test.

    Red flags

    • Doesn't see a problem with using all data.

    Practise it: Fill gaps with a median learned from training data only

  4. junior

    4. In SQL, what's the difference between COUNT(*) and COUNT(column)?

    What it tests: NULL handling in aggregates.

    Model answer and scoring

    COUNT(*) counts rows; COUNT(column) counts non-null values in that column. The difference is the number of missing values, which is a quick profiling check.

    Strong answers

    • Uses it as a profiling tool.

    Red flags

    • Thinks they're the same.
  5. junior

    5. A numeric column uses -999 for missing. What do you do?

    What it tests: Recognising sentinel values.

    Model answer and scoring

    -999 is a code, not a measurement. I convert it to a real missing value with a documented rule before any statistics, otherwise averages are badly wrong.

    I check the documentation for other codes such as 0 or 9999 and ask if unsure.

    Strong answers

    • Converts sentinel to missing.
    • Checks for other codes.

    Red flags

    • Leaves -999 in averages.
  6. senior

    6. Income is missing more often for high earners. How does that affect cleaning choices?

    What it tests: Missingness mechanisms.

    Model answer and scoring

    When missingness depends on the value itself, filling with the median biases incomes downward and dropping rows biases the sample.

    I'd report the missingness pattern, keep a missing indicator, and agree with the analyst on a method, rather than picking a fill silently.

    Strong answers

    • Explains bias.
    • Keeps an indicator and reports.

    Red flags

    • Fills with the mean without comment.

    Practise it: Fill gaps with a median learned from training data only

  7. junior

    7. What is the difference between an empty string and a missing value, and when do you convert one to the other?

    What it tests: Precision about blanks.

    Model answer and scoring

    An empty string is a recorded value; missing means nothing was recorded. Tools treat them differently in joins and counts.

    I convert blanks to missing only where a rule says so, typically after trimming keys so blank keys never match each other.

    Strong answers

    • Explains both.
    • Converts by rule.

    Red flags

    • Treats them as identical everywhere.

    Practise it: Join orders to customers without matching blanks

  8. mid

    8. A region column has missing values. The dashboard needs a region for every visit. What do you do?

    What it tests: Labelling unknown categories.

    Model answer and scoring

    I label missing regions explicitly as unknown so they are visible as their own group, rather than assigning them to a real region.

    Numeric fields in the same rows, such as duration, stay missing; an unknown duration is not zero.

    Strong answers

    • Explicit unknown label.
    • Doesn't fill numbers with 0.

    Red flags

    • Assigns the most common region.

    Practise it: Label unknown categories, keep missing numbers missing

  9. junior

    9. A required field is missing in 2% of rows. What happens to those rows?

    What it tests: Applying required-field rules.

    Model answer and scoring

    They go to the exception report with a missing-field reason, in the declared rule order, and are excluded from the clean output.

    I report the count and ask the source owner to fix the export.

    Strong answers

    • Quarantines with a reason.
    • Reports counts.

    Red flags

    • Invents a default value.

    Practise it: Referential integrity with explicit exceptions

  10. mid

    10. How do SQL and pandas differ in handling missing values in aggregates and comparisons?

    What it tests: Tool semantics.

    Model answer and scoring

    Both skip missing values in sums and means by default. Comparisons with NULL in SQL are unknown, so WHERE drops them; in pandas comparisons with NaN return False.

    The biggest difference is merges: pandas matches NaN keys to each other, SQL never matches NULL keys.

    Strong answers

    • Aggregates, comparisons and merges.

    Red flags

    • Says both behave the same.

Model answers are original study material for practice. They are not employer-endorsed and don't guarantee an outcome.