def filter(self, items=None, like=None, regex=None, axis=None):
    '\n        Subset rows or columns of dataframe according to labels in\n        the specified index.\n\n        Note that this routine does not filter a dataframe on its\n        contents. The filter is applied to the labels of the index.\n\n        Parameters\n        ----------\n        items : list-like\n            List of axis to restrict to (must not all be present).\n        like : string\n            Keep axis where "arg in col == True".\n        regex : string (regular expression)\n            Keep axis with re.search(regex, col) == True.\n        axis : int or string axis name\n            The axis to filter on.  By default this is the info axis,\n            \'index\' for Series, \'columns\' for DataFrame.\n\n        Returns\n        -------\n        same type as input object\n\n        See Also\n        --------\n        DataFrame.loc\n\n        Notes\n        -----\n        The ``items``, ``like``, and ``regex`` parameters are\n        enforced to be mutually exclusive.\n\n        ``axis`` defaults to the info axis that is used when indexing\n        with ``[]``.\n\n        Examples\n        --------\n        >>> df = pd.DataFrame(np.array(([1,2,3], [4,5,6])),\n        ...                   index=[\'mouse\', \'rabbit\'],\n        ...                   columns=[\'one\', \'two\', \'three\'])\n\n        >>> # select columns by name\n        >>> df.filter(items=[\'one\', \'three\'])\n                 one  three\n        mouse     1      3\n        rabbit    4      6\n\n        >>> # select columns by regular expression\n        >>> df.filter(regex=\'e$\', axis=1)\n                 one  three\n        mouse     1      3\n        rabbit    4      6\n\n        >>> # select rows containing \'bbi\'\n        >>> df.filter(like=\'bbi\', axis=0)\n                 one  two  three\n        rabbit    4    5      6\n        '
    import re
    nkw = com.count_not_none(items, like, regex)
    if (nkw > 1):
        raise TypeError('Keyword arguments `items`, `like`, or `regex` are mutually exclusive')
    if (axis is None):
        axis = self._info_axis_name
    labels = self._get_axis(axis)
    if (items is not None):
        name = self._get_axis_name(axis)
        return self.reindex(**{name: [r for r in items if (r in labels)]})
    elif like:

        def f(x):
            return (like in to_str(x))
        values = labels.map(f)
        return self.loc(axis=axis)[values]
    elif regex:

        def f(x):
            return (matcher.search(to_str(x)) is not None)
        matcher = re.compile(regex)
        values = labels.map(f)
        return self.loc(axis=axis)[values]
    else:
        raise TypeError('Must pass either `items`, `like`, or `regex`')
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
    List of axis to restrict to (must not all be present).
like : string
    Keep axis where "arg in col == True".
regex : string (regular expression)
    Keep axis with re.search(regex, col) == 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
def filter(self, items=None, like=None, regex=None, axis=None):
    '\n        Subset rows or columns of dataframe according to labels in\n        the specified index.\n\n        Note that this routine does not filter a dataframe on its\n        contents. The filter is applied to the labels of the index.\n\n        Parameters\n        ----------\n        items : list-like\n            List of axis to restrict to (must not all be present).\n        like : string\n            Keep axis where "arg in col == True".\n        regex : string (regular expression)\n            Keep axis with re.search(regex, col) == True.\n        axis : int or string axis name\n            The axis to filter on.  By default this is the info axis,\n            \'index\' for Series, \'columns\' for DataFrame.\n\n        Returns\n        -------\n        same type as input object\n\n        See Also\n        --------\n        DataFrame.loc\n\n        Notes\n        -----\n        The ``items``, ``like``, and ``regex`` parameters are\n        enforced to be mutually exclusive.\n\n        ``axis`` defaults to the info axis that is used when indexing\n        with ``[]``.\n\n        Examples\n        --------\n        >>> df = pd.DataFrame(np.array(([1,2,3], [4,5,6])),\n        ...                   index=[\'mouse\', \'rabbit\'],\n        ...                   columns=[\'one\', \'two\', \'three\'])\n\n        >>> # select columns by name\n        >>> df.filter(items=[\'one\', \'three\'])\n                 one  three\n        mouse     1      3\n        rabbit    4      6\n\n        >>> # select columns by regular expression\n        >>> df.filter(regex=\'e$\', axis=1)\n                 one  three\n        mouse     1      3\n        rabbit    4      6\n\n        >>> # select rows containing \'bbi\'\n        >>> df.filter(like=\'bbi\', axis=0)\n                 one  two  three\n        rabbit    4    5      6\n        '
    import re
    nkw = com.count_not_none(items, like, regex)
    if (nkw > 1):
        raise TypeError('Keyword arguments `items`, `like`, or `regex` are mutually exclusive')
    if (axis is None):
        axis = self._info_axis_name
    labels = self._get_axis(axis)
    if (items is not None):
        name = self._get_axis_name(axis)
        return self.reindex(**{name: [r for r in items if (r in labels)]})
    elif like:

        def f(x):
            return (like in to_str(x))
        values = labels.map(f)
        return self.loc(axis=axis)[values]
    elif regex:

        def f(x):
            return (matcher.search(to_str(x)) is not None)
        matcher = re.compile(regex)
        values = labels.map(f)
        return self.loc(axis=axis)[values]
    else:
        raise TypeError('Must pass either `items`, `like`, or `regex`')