Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Add example usage to DataFrame.filter #12399
Conversation
jreback
added Docs Indexing
labels
Feb 20, 2016
jreback
added this to the
0.18.0
milestone
Feb 20, 2016
jreback
commented on an outdated diff
Feb 20, 2016
| """ | ||
| - Restrict the info axis to set of items or wildcard | ||
| + | ||
| + Subset rows or columns of dataframe according to labels in the index. | ||
| + | ||
| + Note that this routine does not filter a dataframe on its | ||
| + contents. The filter is applied to the labels of the index. | ||
| + This method is a thin veneer on top of :ref:`DateFrame Select | ||
| + <DataFrame.select>` |
|
|
jreback
commented on an outdated diff
Feb 20, 2016
| @@ -2324,15 +2331,44 @@ def filter(self, items=None, like=None, regex=None, axis=None): | ||
| regex : string (regular expression) | ||
| Keep info axis with re.search(regex, col) == True | ||
| axis : int or None |
jreback
Contributor
|
jreback
and 1 other
commented on an outdated diff
Feb 20, 2016
| Notes | ||
| ----- | ||
| - Arguments are mutually exclusive, but this is not checked for | ||
| + The ``items``, ``like``, and ``regex`` parameters should be |
jreback
Contributor
|
jreback
commented on an outdated diff
Feb 20, 2016
jreback
modified the milestone: 0.18.1, 0.18.0
Feb 22, 2016
|
Removed the "thin veneer" comment and added a See Also referring to |
jreback
modified the milestone: 0.18.2, 0.18.1
Apr 18, 2016
|
can you update |
|
Sorry for being a newbie, but update in what way? Do you want me to rebase my |
|
you need to rebase on master first |
|
I updated my branch, but 24hrs later the CI builds are still not complete. Is that unusual or expected? Also the CI build for python 3.5 failed but I don't see how it has anything to do with changes I created. |
|
Travis was having some issues ok now ithe 3.5 build on. numpy master is currently failing but that is ok |
|
can you rebase / update according to comments |
|
can you rebase / update |
|
can you update |
codecov-io
commented
Jun 1, 2016
•
Current coverage is 83.76%@@ master #12399 diff @@
========================================
Files 138 135 -3
Lines 50721 49640 -1081
Methods 0 0
Branches 0 0
========================================
- Hits 42723 41583 -1140
- Misses 7998 8057 +59
Partials 0 0
|
|
As requested, added test for mutually exclusive arguments in DataFrame.filter and added unit tests for same. |
jorisvandenbossche
and 1 other
commented on an outdated diff
Jun 1, 2016
| """ | ||
| import re | ||
| + args = locals().copy() | ||
| + nkw = sum(map(lambda x: operator.getitem(args,x)!=None, ['items', 'like', 'regex'])) |
jorisvandenbossche
Owner
|
jorisvandenbossche
and 1 other
commented on an outdated diff
Jun 1, 2016
| """ | ||
| import re | ||
| + args = locals().copy() | ||
| + nkw = sum(map(lambda x: operator.getitem(args,x)!=None, ['items', 'like', 'regex'])) | ||
| + if nkw == 0: | ||
| + raise TypeError("filter(): must specify at least one keyword argument") |
cswarth
Contributor
|
jorisvandenbossche
and 1 other
commented on an outdated diff
Jun 1, 2016
| @@ -1497,6 +1497,40 @@ def test_to_xarray(self): | ||
| expected, | ||
| check_index_type=False) | ||
| + def test_filter(self): |
jorisvandenbossche
Owner
|
|
Enforcing mutually exclusive arguments in frame.filter() is an incompatible change that is going to break some code, somewhere. Should this be called out in the release notes? I would like to make a case that this API should be deprecated at this time. It adds little value over reindex and select at the expense of an API that is different than just about anything else. |
jreback
commented on the diff
Jun 3, 2016
|
@cswarth yes pls add a whatsnew note about the mutually exclusive args. |
|
already slated to deprecate in 0.19.0: pydata#12401 |
jreback
closed this
in 103f7d3
Jun 3, 2016
|
thanks @cswarth |
cswarth commentedFeb 20, 2016
Updates doc comments for
DataFrame.filterand adds usage examples.Fixed errors identified by
flake8and correctly rebase my branch before issuing PR.DataFrame.filter(items=None, like=None, regex=None, axis=None)¶Subset rows or columns of dataframe according to labels in the index.
Note that this routine does not filter a dataframe on its contents. The filter is applied to the labels of the index. This method is a thin veneer on top of DateFrame Select
items : list-like
like : string
regex : string (regular expression)
axis : int or None
same type as input object with filtered info axis
Notes
The
items,like, andregexparameters should be mutually exclusive, but this is not checked.axisdefaults to the info axis that is used when indexing with[].Examples
>>> df one two three mouse 1 2 3 rabbit 4 5 6>>> # 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