Data Science Data Wrangling and Preprocessing 2 — Questions and Answers
Question 1: A column of customer ages contains the value 999 for records where age was unknown. What is this an example of?
- A sentinel value encoding missing data (Correct answer)
- A valid outlier
- A categorical variable
- A normalized feature
Correct answer: A sentinel value encoding missing data
Sentinel values like 999 are placeholders that secretly encode missing or unknown data and should be converted to NaN before analysis.
Question 2: In pandas, which method removes rows containing any missing values from a DataFrame?
- df.dropna() (Correct answer)
- df.fillna()
- df.isnull()
- df.drop_duplicates()
Correct answer: df.dropna()
dropna() drops rows (or columns) that contain NaN values by default.
Question 3: You merge two tables on a customer ID, but some IDs exist only in the left table. Which join keeps all left-table rows?
- Left join (Correct answer)
- Inner join
- Right join
- Cross join
Correct answer: Left join
A left join retains every row from the left table and fills unmatched right-table columns with nulls.
Question 4: A date column is stored as strings like '2026-06-30'. What preprocessing step lets you extract the month easily?
- Convert the column to a datetime type (Correct answer)
- One-hot encode the strings
- Standardize the column
- Drop the column
Correct answer: Convert the column to a datetime type
Parsing strings into a datetime type exposes attributes like .month, .year, and .dayofweek.
Question 5: Which technique replaces missing numeric values with the column's median?
- Median imputation (Correct answer)
- Min-max scaling
- Label encoding
- Binning
Correct answer: Median imputation
Median imputation fills NaNs with the median, which is robust to outliers compared to the mean.
Question 6: Why is the median often preferred over the mean for imputing a skewed income column?
- It is less affected by extreme high values (Correct answer)
- It is always larger than the mean
- It removes the need for scaling
- It converts the column to categorical
Correct answer: It is less affected by extreme high values
The median is resistant to outliers, so skewed distributions don't distort the imputed value as much as the mean would.
Question 7: What does 'tidy data' mean in the context of data wrangling?
- Each variable is a column and each observation is a row (Correct answer)
- All values are numeric
- There are no missing values
- The data is sorted alphabetically
Correct answer: Each variable is a column and each observation is a row
Tidy data has one variable per column, one observation per row, and one observational unit per table.
A column of customer ages contains the value 999 for records where age was unknown.
What is this an example of?