pbPassingBI
/
8 questions

Wrangling & cleaning — quiz

8 questions covering this module. Missing values, duplicates, text and types.

  1. mean() on 100 values with 40 missing divides by:

    1. 100
    2. 60
    3. 40
    4. It errors

    Answer: 60 — Missing values are skipped entirely.

  2. df.dropna() with no arguments removes:

    1. Empty columns
    2. Any row containing at least one NaN
    3. Only fully empty rows
    4. Duplicates

    Answer: Any row containing at least one NaN — On a wide table this can remove most of the data.

  3. To keep the most recent record per email:

    1. drop_duplicates() alone
    2. Sort by date, then drop_duplicates(keep="last")
    3. dropna()
    4. groupby(email)

    Answer: Sort by date, then drop_duplicates(keep="last") — Without sorting, which row survives is arbitrary.

  4. duplicated(keep=False) marks:

    1. The first copy only
    2. Every copy including the first
    3. Nothing
    4. Only nulls

    Answer: Every copy including the first — Useful for inspecting all duplicates together.

  5. Why does str.contains() fail on some columns?

    1. Wrong dtype
    2. The column contains NaN — pass na=False
    3. Regex not enabled
    4. Column too long

    Answer: The column contains NaN — pass na=False — Missing values raise unless you tell it how to treat them.

  6. str.split(" ", n=1, expand=True) returns:

    1. A list
    2. A DataFrame of the split parts
    3. A string
    4. A Series of lists

    Answer: A DataFrame of the split parts — expand=True gives columns you can assign directly.

  7. errors="coerce" does what to unparseable values?

    1. Raises an error
    2. Converts them to NaN
    3. Leaves them as text
    4. Drops the row

    Answer: Converts them to NaN — Which lets the rest of the column convert.

  8. Why pass format= to to_datetime?

    1. It is faster only
    2. To avoid ambiguous day/month misparsing
    3. It is required
    4. To handle nulls

    Answer: To avoid ambiguous day/month misparsing — 03/04/2024 is ambiguous, and pandas may guess inconsistently.