Examples
Returning a Series of booleans using only a literal pattern.

In [1]:
import numpy as np
import pandas as pd
In [2]:
s1 = pd.Series(['Tiger', 'fox', 'house and men', '20', np.NaN])
s1.str.contains('ox', regex=False)
Out[2]:
0    False
1     True
2    False
3    False
4      NaN
dtype: object

Returning an Index of booleans using only a literal pattern.

In [3]:
ind = pd.Index(['Tiger', 'fox', 'house and men', '20.0', np.NaN])
ind.str.contains('20', regex=False)
Out[3]:
Index([False, False, False, True, nan], dtype='object')

Specifying case sensitivity using case.

In [4]:
s1.str.contains('oX', case=True, regex=True)
Out[4]:
0    False
1    False
2    False
3    False
4      NaN
dtype: object

Specifying na to be False instead of NaN replaces NaN values with False. If Series or Index does not contain
NaN values the resultant dtype will be bool, otherwise, an object dtype.

In [5]:
s1.str.contains('ox', na=False, regex=True)
Out[5]:
0    False
1     True
2    False
3    False
4    False
dtype: bool

Returning ‘house’ or ‘fox’ when either expression occurs in a string.

In [6]:
s1.str.contains('house|fox', regex=True)
Out[6]:
0    False
1     True
2     True
3    False
4      NaN
dtype: object

Ignoring case sensitivity using flags with regex.

In [7]:
import re
s1.str.contains('MEN', flags=re.IGNORECASE, regex=True)
Out[7]:
0    False
1    False
2     True
3    False
4      NaN
dtype: object

Returning any digit using regular expression.

In [8]:
s1.str.contains('\d', regex=True)
Out[8]:
0    False
1    False
2    False
3     True
4      NaN
dtype: object

Ensure pat is a not a literal pattern when regex is set to True. Note in the following example one might
expect only s2[1] and s2[3] to return True. However, ‘.0’ as a regex matches any character followed by a 0.

In [9]:
s2 = pd.Series(['60', '60.0', '61', '61.0', '45'])
s2.str.contains('.0', regex=True)
Out[9]:
0     True
1     True
2    False
3     True
4    False
dtype: bool