How would you handle 10% null values in a key column?
This tests your understanding of data cleaning trade-offs. First, investigate the cause of nulls. Then, discuss simple imputation (mean/median) vs. discarding rows, weighing pros and cons. A red flag is jumping to a solution without asking about the data.
What's really being asked
This question tests your practical data handling skills, not just theoretical knowledge. The interviewer wants to see if you think about the implications of your choices. Do you investigate first, or just apply a formula? Can you articulate the trade-offs between simple methods like dropping data vs. imputing it with a mean or median? At 10% missing data, your choice has a real impact on the final dashboard.
The full answer
A strong answer has a clear, ordered structure. First, state the need to investigate the cause of the nulls—are they random, or is there a pattern (e.g., all from one specific device)? Second, explicitly state that dropping 10% of the data is usually too high a price to pay and should be avoided. Third, propose univariate imputation as a good starting point. Discuss the main strategies: using the mean (good for normally distributed data), the median (better for skewed data with outliers), or a constant value (e.g., 0, if that makes sense in the context). Fourth, explain the pros and cons of the chosen method, such as how using the mean can reduce variance and pull the distribution towards the center.
The mistakes people make
A major red flag is jumping to a solution without asking questions. For example, "I'd just replace them with the mean." This shows a lack of critical thinking about the data's distribution. Another weak answer is suggesting to drop all rows with nulls. Losing 10% of your data is significant and this approach ignores the potential value in the incomplete rows. Suggesting overly complex multivariate imputation (e.g., using scikit-learn's IterativeImputer) without first justifying why simple methods are insufficient is also a sign of inexperience. Start simple.
What usually comes next
"How would your answer change if 50% of the data was null?" (At this point, imputation is very risky and the data source's integrity is questionable; the column might need to be dropped). "What if the column wasn't numerical, but categorical?" (Impute with the mode/most frequent value, or a new category like 'Unknown'). "How would you implement this in Python?" (Mention pandas.fillna() or scikit-learn's SimpleImputer).
A concrete example
Imagine a 'user_age' column where 10% of values are null. The age distribution is skewed right by a few very high values. Dropping the rows is not ideal as we'd lose 10% of our users. Using the mean age (e.g., 45) would be biased upwards by the outliers. A better choice is to impute with the median age (e.g., 35), as it's more robust to outliers and better represents the central tendency of the skewed data. You could implement this with df['user_age'].fillna(df['user_age'].median(), inplace=True).
Interview question
A key numerical column in your dataset has 10% null values. What is the best initial step to take?
- a.Drop all rows with null values to create a clean, complete dataset for analysis.
- b.Investigate the cause and distribution of the nulls to inform your handling strategy.Correct
- c.Immediately fill the nulls with the column's median, as it is robust to outliers.
- d.Immediately fill the nulls with the column's mean, as it is a standard default.
Why? this is the answer
The correct first step is always to investigate why data is missing before applying a solution. Dropping 10% of rows is a significant data loss, and imputing with the mean or median without understanding the data's distribution is premature.
Just read this? Test yourself on what you have been reading.
Read the original → scikit-learn.org
- #data science
- #analytics
- #data cleaning
- #etl
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on data science — each one lists the topics its interview covers.
See open roles