BuildlyBuildly
DashboardExercisesProfileHelp
Back to all

Practice: CSV Cleanup

Drills tagged with this skill, unpassed first. Pass them all to mark the skill ready for scenarios.

Module 3: Importing & Handling Files

0/3 done
Exercises (0/3)
  • 1
    Remove Duplicate Rows
    Context. A CSV export double-counted some records — the exact same row appears more than once. Your task. Write drop_duplicate_rows(df) that returns a DataFrame with duplicate rows removed, keeping the first occurrence of each. Example. If (Alice, NYC) appears twice, the result keeps just the first one. Notes. A row is a duplicate only if every column matches. Preserve the order of the rows that are kept. No duplicates → df unchanged.
    7 min· 10 XP
  • 2
    Tidy Column Headers
    Context. A CSV arrived with messy column headers — stray spaces, inconsistent casing, spaces inside names — making columns awkward to reference. Your task. Write tidy_headers(df) that returns the DataFrame with every column name cleaned: surrounding whitespace stripped, lowercased, and inner spaces replaced with underscores. Example. " First Name " → "first_name", "AGE" → "age". Notes. Only the headers change — the row data is untouched. Already-clean headers stay as they are.
    7 min· 10 XP
  • 3
    Fix a Numeric Column
    Context. A price column was read from CSV as text because the numbers contain thousands separators ("1,200"). You can't do math on it until it's numeric. Your task. Write fix_price_column(df) that returns the DataFrame with the price column converted to integers — strip the commas first, then change the type. Example. "1,200" → 1200, "980" → 980. Notes. Only the price column changes. Every value is a clean integer once the commas are gone.
    7 min· 10 XP