-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Documentation for .iloc is misleadingly incomplete #8956
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
Comments
yep that was an oversight iloc can take a boolean array want to do a pr to add a doc example and update? |
Sure, I'll give it a shot. |
Is |
Yes, for the example here, the But in general, I think the use case where this can come in handy is if you want to index multiple axes with mixed positional/boolean indexing. Eg if you want to combine iloc on the columns with boolean on the rows:
|
While adding a brief mention of boolean indexers to Numpy is explicit, "Boolean arrays must be of the same shape as the initial dimensions of the array being indexed", but the examples below suggests that is not true. I actually don't know what the hell numpy is doing in this case - it looks totally unexpected. pandas.Series behaves rationally, in my opinion. But is this silent 'leftmost-favored' behavior explicitly documented? If not, should it be?
|
NVM the numpy example, I realize my example was bogus b/c it passed an array as the index. This example works as documented.
|
On Tue, Dec 2, 2014 at 9:11 PM, cswarth [email protected] wrote:
Numpy only allows ndarrays of bool as masks, your snippet used a list of |
I rather find the pandas behaviour a bit strange here. Shouldn't the array not have the same length as the series with boolean indexing? |
@jorisvandenbossche what do you find strange? the boolean array must be equal to the length of the axis |
I'm probably doing something wrong, but I dont think that's true.
|
@cswarth technically that's ok but I think it should really validate the len(boolean indexer) == len(series). numpy actually coerces the indexer which is odd (e.g. this is like indexing [1,0,1])
|
exactly that, the boolean array does apparantly not need to be of the same length
That is what @immerrr said above (#8956 (comment)), numpy only does boolean indexing with arrays, not with lists (so with the array, it is working in the same way as in pandas):
UPDATE: ah, you opened a new issue for that: #8976 |
closed by #8970 |
The documentation for
.loc
at http://pandas.pydata.org/pandas-docs/version/0.15.1/indexing.html#different-choices-for-indexing should mention that.iloc
also takes a boolean array instead of insisting that it is "strictly integer position based".Unlike
.loc
immediately above, no mention is made of "A boolean array"This is incorrect as later in the same document an example uses
.iloc
andisin
to retrieve elements from a Series. isin returns a list of booleans (well, strictly it is a numpy.ndarray, but converting to a list works as well)The text was updated successfully, but these errors were encountered: