-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
0.13.1: DataFrame.xs() ValueError: Cannot retrieve view (copy=False) #6894
Comments
|
I am bending over backwards trying to assign something to a column for rows where the second level in the MultiIndex has a particular value. For the first level, I can do it easily with .loc. How can I do it for the second level? |
in reality this option shouldn't exist at all I think maybe I'll take it out |
@jreback no "may be". Take it out, please. |
in master do this: http://pandas.pydata.org/pandas-docs/dev/ you can swap levels assign then swap back in other versions |
Got it. How expensive is swaplevel? Does it create a copy of everything? |
swap level is cheap |
Thanks! |
ok going to leave open to remove the copy option from xs |
Why doesn't this work?
|
Never mind, somehow this worked:
The funny thing is that if I use a row indexer like
I would have to do
Why the disconnect? |
can u make an example that can be easily copy-pasted thanks |
Sorry, I don't have an easy example. That being said, I figured out how to do things like that: If I reset_index by moving that index level into columns, it becomes MUCH easier to do what I want because I always issue data_frame.loc[rows, column], with rows being a boolean series with the same index as data_frame. What makes interfaces somewhat non-intuitive is that .loc[index_value, column] works somewhat differently from .loc[rows, column], but that might be by design. |
@bluefir not sure what you mean when you reset_index you are changing the index what do you mean by rows and index_value? |
This code snipped seems to work fine:
This would not work:
I tried some other things, but it was really hard trying to get it work with the MultiIndex. First and foremost, for most things I need to sort it first. Anyway, it's not a big deal. Just me learning pandas :-) |
swap level returns a new frame (as do almost all pandas operations) |
I have python 2.7.6 and pandas 0.13.1 on Windows 7.
The text was updated successfully, but these errors were encountered: