-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Label slices on Series with MultiIndex #8539
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
docs are here: http://pandas.pydata.org/pandas-docs/dev/indexing.html#multiindexing-using-slicers this is a 2-d structure so what you are writing is ambiguous at best what if you had a MultiIndex in 2 dimensions? using MultiIndex slicers this is easily accomplishes though requires pandas >= 0.14 |
Ah! Thanks. Unfortunately I have 0.13, at least for a while. Given that as long as I use single labels it works (e.g. |
you can use a tuple to specify the various axes snd a list of tuples their is no ambiguity in a series but the syntax works for multi dimensions and is much more clear the syntax you are using really shouldn't be allowed IMHO but remains for back compat best bet is to upgrade |
@jreback this is a Series, not a DataFrame (so 1d structure), so I think what the OP did should work given pandas >= 0.14 (and it does also work) without an index slicer. Why shouldn't this be allowed? |
This is fixed in 0.15.0 by #8132 Yes this is valid syntax for a Series (only)
|
I have a Series with a MultiIndex like this:
And I'd like to get, for example, the rows where
hour=1, year=2011, weekday=[1,2,3,4]
Intuitively, I would do this:
a.loc[1,2011,1:4]
which would work in a 4-dimensional numpy array. Unfortunately it raises the error:Even If I try suppling the index list instead of a slice:
a.loc[0,2011,[1,2,3,4]]
I get an error:unhashable type: 'list'
Is there a reason why this syntax is not supported? How can I select labels slices in a MultiIndex?
The text was updated successfully, but these errors were encountered: