BuildlyBuildly
DashboardExercisesProfileHelp
Back to all

Practice: Transform Columns

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

Module 2: Data Analytics

0/3 done
Exercises (0/3)
  • 1
    Convert Column to Float
    Context. A CSV loaded every column as strings; you need price as floats so you can add them up. Your task. Write prices_as_float(df) that returns the price column as a Series of floats. Example. ["10.5", "20"] → [10.5, 20.0]. Notes. Use .astype() to convert dtype. Empty input → empty Series.
    7 min· 10 XP
  • 2
    Clean a Text Column with apply
    Context. A user table where names are messy (" alice ", "BOB"); clean each to a consistent format. Your task. Write clean_names(df) that returns the name column with each value stripped of surrounding whitespace and converted to title case. Example. " alice " → "Alice". "BOB" → "Bob". " JANE doe" → "Jane Doe". Notes. Use .apply() to run a function across the column. Empty df → empty Series.
    7 min· 10 XP
  • 3
    Replace Values with a Mapping
    Context. A survey used country codes ("US", "UK", "IN") but the final report needs full names. Your task. Write expand_country_codes(df, mapping) that returns the country column with each code replaced by its full name from the mapping dict. Example. codes ["US", "IN"], mapping {"US": "United States", "IN": "India"} → ["United States", "India"]. Notes. Codes not in the mapping are left unchanged. Empty mapping → all codes pass through unchanged.
    7 min· 10 XP