pandas_select.label.StartsWith

class StartsWith(pat, case=True, axis='columns', level=None)[source]

Select labels that start with a prefix.

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

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

  • 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

EndsWith

Same as StartsWith, but tests the end of string.

Notes

If applied to a MultiIndex with level=None, all the levels will be tested.

Examples

>>> df = pd.DataFrame({"bat": [1], "Bear": [1], "cat": [1]})
>>> df
   bat  Bear  cat
0    1     1    1
>>> df[StartsWith("b")]
   bat
0    1
>>> df[StartsWith("b", case=False)]
   bat  Bear
0    1     1