pandas_select.label.Match

class Match(pat, flags=0, axis='columns', level=None)[source]

Select labels that match a 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.

  • 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.match()

Base implementation

Contains

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

Examples

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