Recall & Review
beginner
What does the
str.contains() method do in Pandas when used with regex?It checks each string in a Series to see if it contains a pattern defined by a regular expression, returning a Series of True or False values.
Click to reveal answer
beginner
How do you use regex to extract a pattern from a Pandas Series?
Use the
str.extract() method with a regex pattern. It returns a DataFrame with the matched groups.Click to reveal answer
beginner
What is the purpose of the
str.replace() method with regex in Pandas?It replaces parts of strings that match a regex pattern with a specified replacement string.
Click to reveal answer
intermediate
How can you filter rows in a DataFrame where a column matches a regex pattern?
Use
df[df['column'].str.contains('pattern', regex=True)] to keep rows where the pattern is found.Click to reveal answer
intermediate
What does setting
na=False do in str.contains()?It treats missing values (NaN) as False, so they don't cause errors and are excluded from matches.
Click to reveal answer
Which Pandas method extracts regex groups from a Series?
✗ Incorrect
str.extract() pulls out matching groups from strings using regex.
What does
str.contains('abc', regex=True) return?✗ Incorrect
It returns True or False for each string depending on if 'abc' is found.
How do you replace all digits in a Series with '#' using regex?
✗ Incorrect
Use str.replace() with regex pattern '\d' to replace digits.
What happens if you use
str.contains() on a Series with NaN values without na=False?✗ Incorrect
By default, it returns NaN for NaN values, not an error. Use na=False to treat NaN as False.
Which method would you use to check if a string starts with a pattern using regex?
✗ Incorrect
str.match() checks if the entire string matches a regex pattern, often used for start matches.
Explain how to filter a Pandas DataFrame column to keep only rows where the text matches a regex pattern.
Think about using a method that returns True/False for each row and then selecting rows.
You got /4 concepts.
Describe how to extract parts of strings from a Pandas Series using regex groups.
Focus on the method that pulls out matching parts instead of just checking presence.
You got /4 concepts.