-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Indexing MultiIndex level depends on chosen level #12827
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
This might actually not be related to the SO question: I tested on 0.14.1, and it behaves the same (while the SO question refers to a change from 0.15.2). |
By ONLY passing a selector on the first level you are getting a de-leveling.
|
Sure, but is there a justification for the incoherent behaviour? |
how is this 'incorherent'? its as expected, you are getting exactly what you asked for. |
If
I find this quite unexpected. Compare with a three-dimensional numpy array: As far as I can tell, the behaviour is also useless and (certainly to me) annoying: there is no way having two levels which I know have each only one value (because I explicitly indexed it) is useful. Oh, and by the way (but I am not sure it is the same problem).
In general, in Python, wouldn't you expect indexing with |
try the same with |
I know how to get what I need. I'm just saying there is an inconsistency. Which also hinders writing more abstract code. For instance, if I write the function
... I will get differently shaped indices depending on the value of |
pls read the documentation, the point is it is supposed to drop levels. |
May I ask you a pointer? I did look at http://pandas.pydata.org/pandas-docs/stable/advanced.html before complaining. The point is precisely I want to drop levels. (by the way: you don't need to get too abstract: how do you get |
not really sure what you want.
|
I want In other words, I want the number of levels returned to be "initial_number_of_levels - number_of_scalars_passed" independently from the first indexer being or not a scalar. |
@toobaz I have no idea what you want. I have given you the tools to look thru things. |
Funny... seems so obvious to me :-) |
@joshuamosesb I have answered there... this bug is actually unrelated |
After multiple times I incurred in this bug, I happened to notice that my example in the above comment could be misinterpreted (it refers to the three-levels example, not the initially given two-levels one)... so since I bet this bug will be reconsidered sooner or later, let me add a clearer example, for the records. Take
With the current syntax, it is impossible to get the result of Compare for instance with See this "discussion" for a more complete argument. |
(fully indexed) In [2]: ss = pd.Series(range(4),
...: index=pd.MultiIndex.from_product([[1,2], [1,2]]))
...:
In [3]: df = pd.DataFrame({10 : ss, 11 : ss})
In [4]: ss.loc[:, 1].index.__class__
Out[4]: pandas.core.indexes.numeric.Int64Index
In [5]: df.loc[(slice(None), 1), 10].index.__class__
Out[5]: pandas.core.indexes.multi.MultiIndex
In [6]: df[10].loc[(slice(None), 1)].index.__class__
Out[6]: pandas.core.indexes.numeric.Int64Index (the above cannot be tested without specifying the columns because of #16396) |
The OP code example in both calls now return an |
Code Sample, a copy-pastable example if possible
Expected Output
The first: the level I am indexing on should disappear from the index.
This is related to http://stackoverflow.com/q/36459311/2858145 (I think)
output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: