Data Cleaning Exercises

Module 18

Python and pandas cleaning

Nullable dtypes, explicit parsing, masks, merge validation and reusable functions.
  1. Override the pandas defaults that change your data

    Recognize the pandas defaults that silently differ from cleaning rules (null-key merges, whitespace, NA strings, float money) and override each explicitly. · 10 min

  2. Boolean masks and .loc

    Select and update rows with boolean masks and .loc, without chained-assignment surprises. · 8 min

  3. Nullable dtypes in practice

    Use Int64, boolean and string dtypes so integers stay exact and missing values stay explicit. · 8 min

  4. merge with validate and indicator

    Use merge options that make join problems visible. · 6 min

Module 18 quiz

Practice questions: choose an answer and check it to see the explanation. Nothing here is timed or graded.

  1. 1. pd.Series([1, None]).dtype with default settings is?
  2. 2. df[df['amount'] > 100]['flag'] = True does not change df. Why?
  3. 3. Why pass dtype="string" for id columns in read_csv?
  4. 4. df['x'].str.strip() on a Series with a missing value returns what for that row?
  5. 5. Why write cleaning as a function clean(df) -> dict of DataFrames?
  6. 6. pd.to_datetime(df['d']) parses "03/04/2026" for UK rows as March 4. Why?