Skip to content

DOC: Improved the docstring of pandas.Series.filter #20148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3924,41 +3924,40 @@ def filter(self, items=None, like=None, regex=None, axis=None):
Parameters
----------
items : list-like
List of info axis to restrict to (must not all be present)
List of axis to restrict to (must not all be present).
like : string
Keep info axis where "arg in col == True"
Keep axis where "arg in col == True".
regex : string (regular expression)
Keep info axis with re.search(regex, col) == True
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
'index' for Series, 'columns' for DataFrame.

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

Examples
--------
>>> df
one two three
mouse 1 2 3
rabbit 4 5 6
>>> 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
one three
mouse 1 3
rabbit 4 6

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

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

See Also
Expand Down