@@ -2357,7 +2357,11 @@ def _reindex_axis(self, new_index, fill_method, axis, copy):
2357
2357
2358
2358
def filter (self , items = None , like = None , regex = None , axis = None ):
2359
2359
"""
2360
- Restrict the info axis to set of items or wildcard
2360
+ Subset rows or columns of dataframe according to labels in
2361
+ the specified index.
2362
+
2363
+ Note that this routine does not filter a dataframe on its
2364
+ contents. The filter is applied to the labels of the index.
2361
2365
2362
2366
Parameters
2363
2367
----------
@@ -2367,19 +2371,57 @@ def filter(self, items=None, like=None, regex=None, axis=None):
2367
2371
Keep info axis where "arg in col == True"
2368
2372
regex : string (regular expression)
2369
2373
Keep info axis with re.search(regex, col) == True
2370
- axis : int or None
2371
- The axis to filter on. By default this is the info axis. The "info
2372
- axis" is the axis that is used when indexing with ``[]``. For
2373
- example, ``df = DataFrame({'a': [1, 2, 3, 4]]}); df['a']``. So,
2374
- the ``DataFrame`` columns are the info axis.
2374
+ axis : int or string axis name
2375
+ The axis to filter on. By default this is the info axis,
2376
+ 'index' for Series, 'columns' for DataFrame
2377
+
2378
+ Returns
2379
+ -------
2380
+ same type as input object
2381
+
2382
+ Examples
2383
+ --------
2384
+ >>> df
2385
+ one two three
2386
+ mouse 1 2 3
2387
+ rabbit 4 5 6
2388
+
2389
+ >>> # select columns by name
2390
+ >>> df.filter(items=['one', 'three'])
2391
+ one three
2392
+ mouse 1 3
2393
+ rabbit 4 6
2394
+
2395
+ >>> # select columns by regular expression
2396
+ >>> df.filter(regex='e$', axis=1)
2397
+ one three
2398
+ mouse 1 3
2399
+ rabbit 4 6
2400
+
2401
+ >>> # select rows containing 'bbi'
2402
+ >>> df.filter(like='bbi', axis=0)
2403
+ one two three
2404
+ rabbit 4 5 6
2405
+
2406
+ See Also
2407
+ --------
2408
+ pandas.DataFrame.select
2375
2409
2376
2410
Notes
2377
2411
-----
2378
- Arguments are mutually exclusive, but this is not checked for
2412
+ The ``items``, ``like``, and ``regex`` parameters are
2413
+ enforced to be mutually exclusive.
2379
2414
2415
+ ``axis`` defaults to the info axis that is used when indexing
2416
+ with ``[]``.
2380
2417
"""
2381
2418
import re
2382
2419
2420
+ nkw = sum ([x is not None for x in [items , like , regex ]])
2421
+ if nkw > 1 :
2422
+ raise TypeError ('Keyword arguments `items`, `like`, or `regex` '
2423
+ 'are mutually exclusive' )
2424
+
2383
2425
if axis is None :
2384
2426
axis = self ._info_axis_name
2385
2427
axis_name = self ._get_axis_name (axis )
0 commit comments