A telecom's plan names are s = pd.Series(["Max+ 10GB", "Max 20GB", None, "Mini 5GB"]). What do print(s.str.contains("Max+", na=False).sum()) and print(s.str.contains("Max+", regex=False, na=False).sum()) print?
Show the answer and explanation
Correct answer: C, 2 and 1: as a regex, "Max+" means 'Ma' then one or more 'x', so "Max 20GB" also matches; regex=False matches the literal text, and na=False makes the None row False.
Explanation Pandas
Series.str.contains treats the pattern as a regular expression by default. In regex, + means 'one or more of the previous character', so "Max+" matches 'Ma' followed by one or more 'x'. Both "Max+ 10GB" and "Max 20GB" contain "Max", so the first count is 2. With regex=False the pattern is a literal substring, and only "Max+ 10GB" matches: 1.
Missing values: on an object column, str.contains returns a missing value for None/NaN rather than True or False (pandas 3's default str dtype returns False instead). na=False turns it into False, giving a clean boolean mask. Without it, using the result to index rows (s[s.str.contains(...)]) can fail with an error about NA values in the mask.
| Pattern | regex=True (default) | regex=False |
|---|---|---|
| "Max+" | 'Ma' + one or more 'x' | literal Max+ |
| "v2.1" | '.' matches any character, so v2x1 matches | literal v2.1 |
| "$9.99" | $ anchors the end, so it never matches | literal $9.99 |
Why the other answers fail: the default is regex matching, not substring search. A quantifier such as + can follow a single character; it does not need a group. regex=False disables all special characters, not only some of them.
If you need regex features and literal text together, escape the literal part with re.escape("Max+"). For case-insensitive matching add case=False.
Interview tip: product names, SKUs and prices often contain +, ., ( or $; mention regex=False or re.escape and na=False whenever you build text filters or keyword-based labels in pandas.