pandas_select.label.Contains

class Contains(pat, case=True, flags=0, regex=True, axis='columns', level=None)[source]

Select labels that contain a pattern or regular expression.

Parameters
  • pat – Character sequence. Regular expressions are not accepted.

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

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

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

  • axis (default 'columns') – Axis along which the function is applied, {0 or ‘index’, 1 or ‘columns’}

  • level (optional) – Either the integer position of the level or its name. It should only be set if axis targets a MultiIndex, otherwise a IndexError will be raised.

See also

pandas.Series.str.contains()

Base implementation

Match

Analogous, but stricter, relying on re.match() instead of re.search().

Examples

>>> df = pd.DataFrame({"Mouse": [1], "dog": [1], "house and parrot": [1]})
>>> df
   Mouse  dog  house and parrot
0      1    1                 1
>>> df[Contains("og", regex=False)]
   dog
0    1
>>> df[Contains("house|dog")]
   dog  house and parrot
0    1                 1