Course outline
Module 1
Module 1: Introduction to Data Quality
Introduction to Data Quality
Knowledge check
Q1. Which of the following best describes data quality?
- A. The amount of data stored in a database
- B. The degree to which data is fit for its intended use ✓
- C. The speed at which data can be queried
- D. The number of columns in a dataset
Why: Data quality is measured by how well data meets the needs of its intended purpose, including accuracy, completeness, consistency, and timeliness. Volume, speed, and structure are separate concerns.
Q2. A customer record is missing a phone number. Which data quality dimension does this issue primarily affect?
- A. Accuracy
- B. Completeness ✓
- C. Consistency
- D. Uniqueness
Why: Completeness refers to whether all required values are present. A missing phone number is a gap in the record, which is a completeness issue.
Q3. Two systems record a customer's state as 'California' in one and 'CA' in the other. Which data quality dimension is most directly violated?
- A. Timeliness
- B. Validity
- C. Consistency ✓
- D. Completeness
Why: Consistency means the same information is represented the same way across datasets or systems. Using two different formats for the same state is a consistency problem.
Q4. A dataset contains the same customer listed three times with slightly different spellings of their name. Which dimension is affected?
- A. Uniqueness ✓
- B. Accuracy
- C. Timeliness
- D. Integrity of formatting
Why: Uniqueness measures whether each real-world entity is represented only once. Duplicate records violate this dimension, even when the variations are minor.
Q5. Which of the following is an example of a validity issue?
- A. A date field contains '2025-13-45', which is not a real date ✓
- B. A sales report arrives two days after the reporting deadline
- C. Two departments store the same product price differently
- D. A customer's address is outdated because they moved last year
Why: Validity checks whether values conform to defined rules, such as valid date ranges or formats. Month 13 and day 45 break those rules. The other options describe timeliness, consistency, and accuracy problems respectively.
Module 2
Module 2: Handling Missing Values
Handling Missing Values
Knowledge check
Q1. Which of the following is the most common first step when handling missing values in a dataset?
- A. Deleting every column that contains any missing value
- B. Identifying how many values are missing and where they occur ✓
- C. Replacing all missing values with zero
- D. Converting all missing values to the string 'unknown'
Why: Before choosing a strategy, you need to understand the extent and pattern of missingness. Counting and locating missing values guides whether deletion, imputation, or another approach is appropriate.
Q2. In pandas, which method returns a boolean DataFrame showing True where values are missing?
- A. dropna()
- B. fillna()
- C. isna() ✓
- D. notnull()
Why: isna() (or its alias isnull()) returns True for missing values and False otherwise. notnull() does the opposite, and dropna() and fillna() modify data rather than flag it.
Q3. A column has 2% missing values, and those rows appear to be missing at random. Which approach is usually reasonable?
- A. Keep the column unchanged so the missing values remain as they are
- B. Delete the rows with missing values, since the loss of data is small ✓
- C. Replace every value in the entire dataset with the column mean
- D. Delete the entire dataset and start over
Why: When the proportion of missing data is small and the missingness is random, dropping those rows typically introduces little bias and loses little information.
Q4. Which imputation method replaces missing values in a numeric column with the median of the observed values?
- A. Forward fill
- B. Mean imputation
- C. Median imputation ✓
- D. Mode imputation
Why: Median imputation uses the middle value of the observed data. It is more robust to outliers than mean imputation, which can be skewed by extreme values.
Q5. Why should you be cautious about filling missing values with the overall mean of a column?
- A. The mean cannot be calculated when values are missing
- B. It can reduce the variance of the column and distort relationships with other variables ✓
- C. It always produces negative numbers
- D. It converts numeric columns into text columns
Why: Filling many values with the same mean artificially concentrates the data around that value, shrinking variance and potentially weakening correlations and distorting analysis results.
Module 3
Module 3: Detecting and Treating Outliers
Detecting and Treating Outliers
Knowledge check
Q1. Which of the following is the simplest method for flagging potential outliers in a numeric column?
- A. Computing the mean and standard deviation, then flagging values more than 3 standard deviations from the mean ✓
- B. Sorting the column alphabetically
- C. Removing all rows with missing values
- D. Converting every value to a string
Why: The z-score approach flags values that lie unusually far from the mean, measured in standard deviations. Values beyond about 3 standard deviations are commonly treated as potential outliers.
Q2. What does the interquartile range (IQR) measure?
- A. The difference between the maximum and minimum values
- B. The spread of the middle 50% of the data, calculated as Q3 minus Q1 ✓
- C. The average distance of each point from the median
- D. The total number of unique values in the column
Why: The IQR is the range between the 25th percentile (Q1) and the 75th percentile (Q3). It describes the spread of the central half of the data and is robust to extreme values.
Q3. Using the IQR rule, how are outliers typically defined?
- A. Values below Q1 or above Q3
- B. Values below Q1 minus 1.5 times the IQR, or above Q3 plus 1.5 times the IQR ✓
- C. Values equal to the median
- D. Values that appear only once in the dataset
Why: The common Tukey fence rule marks values lying more than 1.5 times the IQR beyond the first or third quartile as outliers. This threshold is widely used in box plots.
Q4. A dataset contains a salary of 9,000,000 in a column where most values are between 30,000 and 90,000. The value is confirmed to be a data entry error with an extra zero. What is the most appropriate treatment?
- A. Keep it, because outliers should never be changed
- B. Correct the value if the true figure can be determined, otherwise remove or impute it ✓
- C. Replace the entire column with random numbers
- D. Double every other value in the column
Why: Confirmed data entry errors should be corrected when the true value is known. If it cannot be recovered, removing the record or imputing a reasonable value are appropriate treatments.
Q5. Why should you be cautious about removing outliers without investigating them first?
- A. Outliers always contain errors and must be kept
- B. Outliers may be genuine, meaningful observations, and removing them can bias results or hide important patterns ✓
- C. Removing outliers increases the number of columns
- D. Outliers cannot be detected by any statistical method
Why: An outlier may be a data error, but it may also be a rare yet real event, such as a fraud case or a high-value customer. Investigating before removing preserves valid information and avoids biased analysis.
Module 4
Module 4: Standardizing and Formatting Data
Standardizing and Formatting Data
Knowledge check
Q1. Which of the following is the most appropriate way to standardize date values stored as 'Jan 5, 2023', '05/01/2023', and '2023-01-05' in a single column?
- A. Leave them as-is, since dates are readable in any format
- B. Convert all values to a single consistent format such as YYYY-MM-DD using a parsing function ✓
- C. Convert all values to text strings and sort them alphabetically
- D. Delete any rows that do not match the first format found in the column
Why: Standardizing to one consistent format such as ISO 8601 (YYYY-MM-DD) ensures dates can be compared, sorted, and calculated correctly. Mixed formats cause errors in analysis and sorting, and deleting rows would discard valid data.
Q2. What is the main purpose of converting text values to a consistent case (for example, all lowercase) during data cleaning?
- A. To make the data look more professional in reports
- B. To ensure that values like 'New York', 'new york', and 'NEW YORK' are treated as the same category ✓
- C. To reduce the file size of the dataset
- D. To convert numeric values into text
Why: Text comparisons are usually case-sensitive, so the same category written with different capitalization would be counted as separate groups. Consistent casing allows accurate grouping, counting, and matching.
Q3. A column named 'Country' contains the values 'USA', 'United States', 'U.S.A.', and 'us'. What is the best standardization step?
- A. Keep all four values because they are all understandable
- B. Map all variations to a single standard label such as 'United States' using a lookup or replacement table ✓
- C. Remove the column because it contains inconsistent data
- D. Convert the values to numbers
Why: Mapping variant spellings and abbreviations to one canonical label ensures that all records for the same country are grouped together. A replacement or lookup table is the standard approach for this kind of normalization.
Q4. Why is it important to trim leading and trailing whitespace from text fields during standardization?
- A. Whitespace makes the dataset load more slowly in most software
- B. Values such as 'Sales' and 'Sales ' (with a trailing space) would otherwise be treated as different categories ✓
- C. Whitespace is always treated as a missing value
- D. Trailing spaces cause numeric columns to become text
Why: Invisible spaces create hidden differences between values that look identical. Trimming whitespace prevents duplicate categories and mismatched joins or lookups that are hard to spot visually.
Q5. Which data type is most appropriate for a column containing ZIP codes such as '02138' and '90210'?
- A. Integer, because all ZIP codes are numbers
- B. Text (string), because leading zeros are meaningful and would be lost if stored as numbers ✓
- C. Date, because ZIP codes represent locations over time
- D. Boolean, because ZIP codes are either valid or invalid
Why: ZIP codes are identifiers rather than quantities, so arithmetic has no meaning for them. Storing them as numbers would drop leading zeros (for example, '02138' would become 2138), so text is the correct data type.
Module 5
Module 5: Removing Duplicates and Inconsistencies
Removing Duplicates and Inconsistencies
Knowledge check
Q1. Which pandas method is used to identify fully duplicated rows in a DataFrame?
- A. df.drop_duplicates()
- B. df.duplicated() ✓
- C. df.unique()
- D. df.isnull()
Why: df.duplicated() returns a boolean Series marking rows that are duplicates of an earlier row, making it useful for inspecting duplicates before removing them. df.drop_duplicates() removes them, df.unique() works on a single column's values, and df.isnull() checks for missing values.
Q2. By default, which row is kept when using df.drop_duplicates()?
- A. The last occurrence of each duplicate
- B. The first occurrence of each duplicate ✓
- C. A randomly selected occurrence
- D. All duplicate rows are removed, including the original
Why: The default keep parameter is 'first', which retains the first occurrence and removes subsequent duplicates. Setting keep='last' retains the final occurrence, and keep=False removes all duplicates including the original.
Q3. Which approach best handles inconsistent capitalization in a text column such as 'New York', 'new york', and 'NEW YORK'?
- A. Delete all rows containing these values
- B. Convert the column to lowercase or title case before comparing values ✓
- C. Replace each value with a random category
- D. Leave them as they are because pandas detects case automatically
Why: Standardizing case with str.lower() or str.title() makes equivalent values identical so they can be grouped and deduplicated correctly. Pandas does not treat differently cased strings as equal by default, so no automatic detection occurs.
Q4. Why is it important to strip leading and trailing whitespace from text fields before removing duplicates?
- A. Whitespace causes Python to crash during processing
- B. Values like 'Paris' and 'Paris ' are treated as different strings, so true duplicates may be missed ✓
- C. Whitespace is automatically converted to missing values
- D. Whitespace only affects numeric columns
Why: Trailing or leading spaces make visually identical entries unequal in comparisons, so duplicate detection will miss them. Using str.strip() before deduplication ensures consistent matching.
Q5. If you want to check for duplicates based only on the 'email' column rather than all columns, which code is correct?
- A. df.drop_duplicates(subset='email') ✓
- B. df.drop_duplicates(columns='email')
- C. df.remove_duplicates('email')
- D. df.drop_duplicates(by='email')
Why: The subset parameter of drop_duplicates() specifies which columns to consider when identifying duplicates. The other options use parameter names or methods that do not exist in pandas.
Module 6
Module 6: Data Type Conversion and Validation
Data Type Conversion and Validation
Knowledge check
Q1. Which function in pandas is commonly used to convert a column to a numeric data type, turning invalid entries into NaN?
- A. pd.to_numeric(df['col'], errors='coerce') ✓
- B. pd.as_numeric(df['col'], errors='ignore')
- C. df['col'].convert_int()
- D. pd.parse_numbers(df['col'])
Why: pd.to_numeric with errors='coerce' converts values that cannot be parsed as numbers into NaN, which makes invalid entries easy to detect and handle. The other options are not real pandas functions.
Q2. What is the main risk of converting a column containing missing values to a standard integer type in pandas?
- A. Integers cannot store negative numbers
- B. The conversion will always round values to the nearest ten
- C. Missing values cause an error because standard integer types cannot represent NaN ✓
- D. The column will automatically be converted to text
Why: NumPy's standard int64 type has no representation for NaN, so a column with missing values will be stored as float or raise an error. Pandas' nullable 'Int64' dtype is designed to handle this case.
Q3. Which of the following is an example of data validation rather than data type conversion?
- A. Changing a string column of dates into datetime objects
- B. Checking that every age value falls between 0 and 120 ✓
- C. Casting a float column to an integer column
- D. Converting category labels into numeric codes
Why: Validation checks whether values meet defined rules or constraints, such as range limits. Type conversion changes how values are stored, while validation confirms the values are sensible.
Q4. Why is it useful to parse date strings with an explicit format argument, such as pd.to_datetime(col, format='%d/%m/%Y')?
- A. It makes the function run without any memory usage
- B. It removes all duplicate rows automatically
- C. It prevents ambiguous dates like 03/04/2021 from being interpreted in the wrong order ✓
- D. It converts the dates into plain text strings
Why: Formats such as day-first versus month-first can be ambiguous. Specifying the format explicitly ensures the parser reads the components in the intended order and makes parsing faster and more reliable.
Q5. Which check best validates that a categorical column contains only allowed values?
- A. Computing the mean of the column
- B. Using df['col'].isin(allowed_values) to flag rows with unexpected entries ✓
- C. Calling df['col'].astype(float) and ignoring the result
- D. Sorting the column alphabetically
Why: The isin method returns a boolean mask showing which values belong to an allowed set, making it easy to find and flag invalid categories. Means and sorting do not validate membership, and casting to float would fail or produce NaN for text values.
Module 7
Module 7: Feature Preparation for Analysis
Feature Preparation for Analysis
Knowledge check
Q1. Why is it generally recommended to split a dataset into training and test sets before performing feature scaling?
- A. To reduce the total number of rows the model needs to process
- B. To prevent information from the test set leaking into the scaling parameters learned from the training data ✓
- C. Because scaling only works on the test set
- D. To ensure that all features have exactly the same number of unique values
Why: If scaling statistics such as the mean and standard deviation are computed on the full dataset, information from the test set leaks into the training process. Fitting the scaler only on the training data and then applying it to the test data gives an honest estimate of model performance.
Q2. Which encoding method is most appropriate for a nominal categorical feature such as 'color' with values red, green, and blue?
- A. Label encoding that maps red to 1, green to 2, and blue to 3
- B. One-hot encoding that creates a separate binary column for each color ✓
- C. Min-max scaling to the range 0 to 1
- D. Log transformation of each category
Why: Nominal categories have no inherent order. Label encoding would imply a ranking (for example, blue being greater than red), which can mislead models. One-hot encoding represents each category as an independent binary column.
Q3. What is the main purpose of min-max scaling?
- A. To remove outliers from a feature
- B. To convert a numeric feature so its values fall within a fixed range, usually 0 to 1 ✓
- C. To convert text data into numbers
- D. To fill in missing values with the mean
Why: Min-max scaling rescales values using the formula (x - min) / (max - min), placing them in a fixed range. This helps features measured on different scales contribute comparably, which matters for distance-based and gradient-based models.
Q4. A dataset has a 'income' feature where most values are between 20,000 and 80,000, but a few are above 10,000,000. What is a sensible first step to prepare this feature?
- A. Delete the entire income column
- B. Apply a log transformation to reduce the influence of the extreme values ✓
- C. Replace every value with the number 1
- D. Convert the column to text categories
Why: A log transformation compresses large values and reduces skewness, making the distribution more manageable. Deleting the column discards useful information, and converting a numeric feature to text or constants destroys its meaning.
Q5. Why might you create a new feature such as 'age' from a 'date_of_birth' column?
- A. Because raw dates cannot be stored in a database
- B. Because derived features can express meaningful information in a form models can use more directly ✓
- C. Because machine learning models require every feature to be named age
- D. Because dates always contain errors that must be removed
Why: Feature engineering transforms raw data into more informative representations. A date of birth is hard for a model to use directly, while age captures the relevant signal in a numeric form that aligns with the problem being studied.