BuildlyBuildly
DashboardExercisesProfileHelp
Data Science/Module 3: Importing & Handling Files/String Cleanup (Series)1/3
Exercise·7 min·10 XP

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.

Previous
Strip Separators from a Column
Next
Parse a Date Column