pandas.Series.str.contains

pandas 3.1.1 · Series and accessors · method

Check whether each string contains a pattern. Set regex=False to match text literally.

Call syntax

Series.str.contains(pat, case=True, flags=0, na=…, regex=True)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
pat Required
Positional or keyword
str

Specify the substring or regular expression to match.

case Optional
Positional or keyword
Default True
bool

Choose whether uppercase and lowercase must match exactly.

flags Optional
Positional or keyword
Default 0
int

Pass regular-expression modifiers such as re.IGNORECASE.

na Optional
Positional or keyword
scalar

Provide a replacement for missing inputs. When omitted, the result depends on the input dtype.

regex Optional
Positional or keyword
Default True
bool

True treats pat as a regular expression. False searches for literal text.

Returns

Series or Index of boolean values