Extracting with str.extract (regex)
📖 Scenario: You work in a store and have a list of product codes mixed with letters and numbers. You want to pull out just the numbers from each code to analyze sales data.
🎯 Goal: Build a small program that extracts the numeric part from each product code using str.extract with a regular expression.
📋 What You'll Learn
Create a pandas Series called
product_codes with the exact values: 'A123', 'B456', 'C789', 'D012'Create a regex pattern string called
pattern that matches one or more digitsUse
str.extract on product_codes with pattern to get the numbersPrint the extracted numbers as a pandas Series
💡 Why This Matters
🌍 Real World
Stores and businesses often have product codes mixing letters and numbers. Extracting parts of these codes helps analyze sales or inventory.
💼 Career
Data analysts and scientists use regex extraction to clean and prepare text data for analysis in many industries.
Progress0 / 4 steps