Skip to content

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

@lodagro

Description

@lodagro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions