Skip to content
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

Case where xs(copy=False) does not return view. #2117

Closed
lodagro opened this issue Oct 25, 2012 · 2 comments

Comments

@lodagro
Copy link
Contributor

commented Oct 25, 2012

from stackoverflow

In [25]: cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:>>> index = pd.MultiIndex.from_arrays([['a','a', 'b', 'b'], [1,2,1,2]], 
:...                                   names=['first', 'second'])
:>>> data = pd.DataFrame(np.random.rand(len(index)), index=index, columns=['A'])
:>>> print data
:--
                     A
first second          
a     1       0.026915
      2       0.777457
b     1       0.445726
      2       0.243053

In [26]: selected = data.xs(2, level='second', copy=False)

In [27]: selected
Out[27]: 
              A
first          
a      0.777457
b      0.243053

In [28]: selected['A'][0] = 100

In [29]: selected
Out[29]: 
                A
first            
a      100.000000
b        0.243053

In [30]: data
Out[30]: 
                     A
first second          
a     1       0.026915
      2       0.777457
b     1       0.445726
      2       0.243053
@btel

This comment has been minimized.

Copy link

commented Oct 25, 2012

It seems that xs(copy=False) does not work with MultiIndex.

@wesm

This comment has been minimized.

Copy link
Member

commented Nov 3, 2012

This can't be fixed. Would an exception be preferable?

@wesm wesm closed this in 189d04c Nov 3, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.