bigframes.pandas.api.typing.StringMethods.contains#

StringMethods.contains(pat, case: bool = True, flags: int = 0, *, regex: bool = True) T[source]#

Test if pattern or regex is contained within a string of a Series or Index.

Return boolean Series or Index based on whether a given pattern or regex is contained within a string of a Series or Index.

Examples:

>>> import bigframes.pandas as bpd

Returning a Series of booleans using only a literal pattern.

>>> s1 = bpd.Series(['Mouse', 'dog', 'house and parrot', '23', None])
>>> s1.str.contains('og')
0    False
1     True
2    False
3    False
4     <NA>
dtype: boolean

Specifying case sensitivity using case.

>>> s1.str.contains('oG', case=True)
0    False
1    False
2    False
3    False
4     <NA>
dtype: boolean

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

>>> s1.str.contains('house|dog', regex=True)
0    False
1     True
2     True
3    False
4     <NA>
dtype: boolean

Ignoring case sensitivity using flags with regex.

>>> import re
>>> s1.str.contains('PARROT', flags=re.IGNORECASE, regex=True)
0    False
1    False
2     True
3    False
4     <NA>
dtype: boolean

Returning any digit using regular expression.

>>> s1.str.contains('\d', regex=True)
0    False
1    False
2    False
3     True
4     <NA>
dtype: boolean

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.

>>> s2 = bpd.Series(['40', '40.0', '41', '41.0', '35'])
>>> s2.str.contains('.0', regex=True)
0     True
1     True
2    False
3     True
4    False
dtype: boolean
Parameters:
  • pat (str, re.Pattern) – Character sequence or regular expression.

  • case (bool, default True) – If True, case sensitive.

  • flags (int, default 0) – Flags to pass through to the re module, e.g. re.IGNORECASE.

  • regex (bool, default True) – If True, assumes the pat is a regular expression. If False, treats the pat as a literal string.

Returns:

A Series or Index of boolean values indicating

whether the given pattern is contained within the string of each element of the Series or Index.

Return type:

bigframes.series.Series