Data Science Data Cleaning and Preparation 2 — Questions and Answers
Question 1: In pandas, what does df.dropna(thresh=3) do?
- Drops rows that have fewer than 3 non-null values (Correct answer)
- Drops the first 3 rows with any NaN
- Drops columns with more than 3 NaN values
- Replaces NaN with the value 3
Correct answer: Drops rows that have fewer than 3 non-null values
thresh keeps only rows with at least 3 non-null values, dropping those below the threshold.
Question 2: Which technique replaces missing numeric values with the column average?
- Mean imputation (Correct answer)
- One-hot encoding
- Min-max scaling
- Label encoding
Correct answer: Mean imputation
Mean imputation fills missing values using the column's average.
Question 3: A 'duplicate record' in a dataset is best defined as a row that:
- Has identical values across the columns used to identify uniqueness (Correct answer)
- Contains any null value
- Appears in two different files
- Has a numeric outlier
Correct answer: Has identical values across the columns used to identify uniqueness
Duplicates are rows matching on the key columns that define a unique record.
Question 4: Which pandas method removes duplicate rows?
- df.drop_duplicates() (Correct answer)
- df.dropna()
- df.unique()
- df.distinct()
Correct answer: df.drop_duplicates()
drop_duplicates() removes repeated rows from a DataFrame.
Question 5: Converting a column stored as text '2024-01-15' into a datetime type is an example of:
- Type casting / parsing (Correct answer)
- Normalization
- Binning
- Deduplication
Correct answer: Type casting / parsing
Changing a string into a datetime is type casting or parsing.
Question 6: What is the main risk of dropping all rows containing any missing value?
- Significant loss of usable data and potential bias (Correct answer)
- It always improves model accuracy
- It encrypts the dataset
- It creates duplicate rows
Correct answer: Significant loss of usable data and potential bias
Listwise deletion can discard large amounts of data and introduce bias.
Question 7: Standardizing inconsistent category labels like 'USA', 'U.S.A.', and 'United States' is called:
- Data standardization / canonicalization (Correct answer)
- Sampling
- Cross-validation
- Feature extraction
Correct answer: Data standardization / canonicalization
Mapping variant labels to one canonical form is standardization.
In pandas, what does df.dropna(thresh=3) do?