Recall & Review
beginner
What does the
str.contains() method do in pandas?It checks if each string in a pandas Series contains a specified pattern or substring, returning a Series of True or False values.
Click to reveal answer
beginner
How can you make
str.contains() case insensitive?By setting the parameter
case=False, the method ignores case when searching for the pattern.Click to reveal answer
intermediate
What happens if
str.contains() encounters a missing value (NaN) in the Series?By default, it returns
NaN for that position, but you can set na=False to treat missing values as not matching the pattern.Click to reveal answer
beginner
How do you use
str.contains() to filter rows in a DataFrame where a column contains a specific word?Use it inside boolean indexing like
df[df['column'].str.contains('word', na=False)] to keep rows where 'word' appears in 'column'.Click to reveal answer
intermediate
Can
str.contains() use regular expressions for pattern matching?Yes, by default it treats the pattern as a regular expression, allowing complex pattern matching. You can disable this with
regex=False.Click to reveal answer
What does
str.contains('cat') return when applied to a pandas Series?✗ Incorrect
It returns a Series of True or False values showing if 'cat' is found in each string.
How do you ignore case when using
str.contains()?✗ Incorrect
Setting
case=False makes the search case insensitive.What parameter do you use to treat NaN values as False in
str.contains()?✗ Incorrect
The
na=False parameter treats missing values as not matching the pattern.By default, does
str.contains() treat the pattern as a regular expression?✗ Incorrect
By default,
str.contains() uses regex for pattern matching.Which of these filters a DataFrame to rows where 'name' column contains 'John'?
✗ Incorrect
Use
str.contains() with na=False inside boolean indexing to filter rows.Explain how to use
str.contains() to find rows in a DataFrame where a column includes a certain substring, including how to handle missing values and case sensitivity.Think about filtering with True/False and controlling how missing data and letter case affect the search.
You got /4 concepts.
Describe the role of regular expressions in
str.contains() and how to disable them if you want a simple substring search.Consider how regex allows patterns and how to turn it off for plain text matching.
You got /4 concepts.