How to retrieve view of MultiIndex DataFrame

Posted by Henry S. Harrison on Stack Overflow See other posts from Stack Overflow or by Henry S. Harrison
Published on 2013-11-03T22:13:55Z Indexed on 2013/11/04 3:54 UTC
Read the original article Hit count: 222

Filed under:
|

This question was inspired by this question. I had the same problem, updating a MultiIndex DataFrame by selection. The drop_level=False solution in Pandas 0.13 will allow me to achieve the same result, but I am still wondering why I cannot get a view from the MultiIndex DataFrame. In other words, why does this not work?:

>>> sat = d.xs('sat', level='day', copy=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 2248, in xs
    raise ValueError('Cannot retrieve view (copy=False)')
ValueError: Cannot retrieve view (copy=False)

Of course it could be only because it is not implemented, but is there a reason? Is it somehow ambiguous or impossible to implement? Returning a view is more intuitive to me than returning a copy then later updating the original. I looked through the source and it seems this situation is checked explicitly to raise an error.

Alternatively, is it possible to get the same sort of view from any of the other indexing methods? I've experimented but have not been successful.

[edit] Some potential implementations are discussed here. I guess with the last question above I'm wondering what the current best solution is to index into arbitrary multiindex slices and cross-sections.

© Stack Overflow or respective owner

Related posts about python

Related posts about pandas