def filter(self, items=None, like=None, regex=None, axis=None):
import re<EOL>nkw = com.count_not_none(items, like, regex)<EOL>if nkw > <NUM_LIT:1>:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if axis is None:<EOL><INDENT>axis = self._info_axis_name<EOL><DEDENT>labels = self._get_axis(axis)<EOL>if items is not None:<EOL><INDENT>name = self._get_axis_name(axis)<EOL>return self.reindex(<EOL>**{name: [r for r in items if r in labels]})<EOL><DEDENT>elif like:<EOL><INDENT>def f(x):<EOL><INDENT>return like in to_str(x)<EOL><DEDENT>values = labels.map(f)<EOL>return self.loc(axis=axis)[values]<EOL><DEDENT>elif regex:<EOL><INDENT>def f(x):<EOL><INDENT>return matcher.search(to_str(x)) is not None<EOL><DEDENT>matcher = re.compile(regex)<EOL>values = labels.map(f)<EOL>return self.loc(axis=axis)[values]<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>
Subset rows or columns of dataframe according to labels in
the specified index.

Note that this routine does not filter a dataframe on its
contents. The filter is applied to the labels of the index.

Parameters
----------
items : list-like
    Keep labels from axis which are in items.
like : string
    Keep labels from axis for which "like in label == True".
regex : string (regular expression)
    Keep labels from axis for which re.search(regex, label) == True.
axis : int or string axis name
    The axis to filter on.  By default this is the info axis,
    'index' for Series, 'columns' for DataFrame.

Returns
-------
same type as input object

See Also
--------
DataFrame.loc

Notes
-----
The ``items``, ``like``, and ``regex`` parameters are
enforced to be mutually exclusive.

``axis`` defaults to the info axis that is used when indexing
with ``[]``.

Examples
--------
>>> df = pd.DataFrame(np.array(([1, 2, 3], [4, 5, 6])),
...                   index=['mouse', 'rabbit'],
...                   columns=['one', 'two', 'three'])

>>> # select columns by name
>>> df.filter(items=['one', 'three'])
         one  three
mouse     1      3
rabbit    4      6

>>> # select columns by regular expression
>>> df.filter(regex='e$', axis=1)
         one  three
mouse     1      3
rabbit    4      6

>>> # select rows containing 'bbi'
>>> df.filter(like='bbi', axis=0)
         one  two  three
rabbit    4    5      6