In [1]: import pandas as pd, StringIO In [2]: csv = StringIO.StringIO('time,data\n0,10\n1,11\n2,12\n4,14\n5,15\n3,13') In [3]: df = pd.read_csv(csv, index_col='time') In [4]: df Out[4]: data time 0 10 1 11 2 12 4 14 5 15 3 13 In [5]: df.sort(inplace=True) In [6]: df Out[6]: data time 0 10 1 11 2 12 3 13 4 14 5 15
Specifying squeeze=True
returns a view instead of first-class object? Is this by design and if so, why?
As of 0.14.1, inplace=True
is the default (related #5190) for series sorts so the following error will occur by default if squeeze=True
was specified.
In [1]: import pandas as pd, StringIO In [2]: csv = StringIO.StringIO('time,data\n0,10\n1,11\n2,12\n4,14\n5,15\n3,13') In [3]: df = pd.read_csv(csv, index_col='time', squeeze=True) In [4]: df Out[4]: data time 0 10 1 11 2 12 4 14 5 15 3 13 In [5]: df.sort(inplace=True) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-5-850f333de498> in <module>() ----> 1 df.sort(inplace=True) C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\pandas\core\series.pyc in sort(self, axis, ascending, kind, na_position, inplace) 1651 kind=kind, 1652 na_position=na_position, -> 1653 inplace=inplace) 1654 1655 def order(self, na_last=None, ascending=True, kind='quicksort', na_position='last', inplace=False): C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\pandas\core\series.pyc in order(self, na_last, ascending, kind, na_position, inplace) 1684 # GH 5856/5853 1685 if inplace and self._is_cached: -> 1686 raise ValueError("This Series is a view of some other array, to " 1687 "sort in-place you must create a copy") 1688 ValueError: This Series is a view of some other array, to sort in-place you must create a copy
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4