-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Series.__getitem__
semantics vary according to runtime values
#9213
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
you should simply use If you would like to propose an addition to the docs that you think is more clear. all ears. |
It's frustrating also that there's no concise way to index The only spelling I can think of for this is |
I think the indexing is already quite confusing. I supposed we could add a flag, something like
|
I guess that works, even though it feels inefficient (said the premature optimizer!). But for the
|
Looking at this more carefully, it seems you've indeed stumbled on the ambiguity that occurs when your indicies are numeric types. When you do @jreback @shoyer When new users learn pandas, they are instinctively going to slice with In regard to the less extreme suggestion of changing the docs, I think the most simple change would be to introduce |
I only use
I agree, the current indexing semantics are a land-mine. Now that I think about it, I'm not even sure (1) is safe if my column labels are integers, though I guess I usually use strings. It would definitely be a good idea to mention We might also consider making a thorough list of what |
In any case, good |
Your case (1) is in any case safe I think, as this is always label based (so when having an integer column axis, it also works on the labels, not integer location) |
Python developers new to pandas are always going to use |
To bikeshed further, if one had to choose between index or value slicing, what do you guys think the @dandavison While I don't speak for the pandas development team, I can say from experience that this particular behavior is not indicative of my overall personal experiences with |
Series.__getitem__
semantics vary according to runtime values
Depending on the runtime value used in
[
indexing on a series, the semantics may be array-indexing, or slicing based on a MultiIndex. This is extremely error-prone behavior in a very basic operation.Is the answer that production code should always use
.loc
/.ix
instead of[
? If so, I don't think the docs make that clear.See also #3390
The text was updated successfully, but these errors were encountered: