BuildlyBuildly
DashboardExercisesProfileHelp
Back to all

Practice: String Cleanup (Series)

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
    Normalize Text Values
    Context. An email column has inconsistent entries — stray spaces and mixed casing — so the same address looks different across rows. Your task. Write normalize_emails(df) that returns the email column as a Series, with surrounding whitespace stripped and every value lowercased. Example. " Alice@MAIL.com " → "alice@mail.com". Notes. Return a Series, not a DataFrame. Already-clean values pass through unchanged.
    7 min· 10 XP
  • 2
    Strip Separators from a Column
    Context. A phone column has numbers written with all kinds of separators — hyphens and spaces — and you need them as plain digit strings. Your task. Write clean_phone_numbers(df) that returns the phone column as a Series with every hyphen (-) and space removed. Example. "98-765 43210" → "9876543210". Notes. Return a Series. Remove both hyphens and spaces. Values with no separators pass through unchanged.
    7 min· 10 XP
  • 3
    Extract a Pattern
    Context. A label column mixes free text with a four-digit year somewhere inside each value. You want just the year. Your task. Write extract_year(df) that returns a Series with the first four-digit number pulled out of each label. Example. "Report 2021" → "2021", "Q3 2022 update" → "2022". Notes. Return a Series of strings. If a label has more than one number, take the first match. Every label contains at least one four-digit run.
    7 min· 10 XP