s = pd.Series( nr.randint( 0, 10, 5 ), index=nr.randint(0, 10, 5 ) )
s
Output
1 3
7 6
2 0
9 7
1 6
Your Question: Is this (Series.sort
in-place v.s. Series.order
return-new-obj) the only difference between the two methods?
Short Answer: YES. They are functionally equivalent.
Longer Answer:
pandas.Series.sort(): change the object itself (in-place sorting), but returns nothing.
Sort values and index labels by value. This is an inplace sort by default.
Series.order
is the equivalent but returns a new Series.
So
>>> s = pd.Series([3,4,0,3]).sort()
>>> s
outputs nothing. See the answer here for more details.
pandas.Series.order(): dose not change the object, instead it returns a new sorted object.
Sorts Series object, by value, maintaining index-value link. This will return a new Series by default.
Series.sort
is the equivalent but as an inplace method.
The API of sorting is changed, things became cleaner and more pleasant.
To sort by the values, both Series.sort()
and Series.order()
are DEPRECATED, replaced by the new Series.sort_values() api, which returns a sorted Series object.
To summary the changes (excerpt from pandas 0.17.0 doc):
To sort by the values (A * marks items that will show a FutureWarning):
Previous | Replacement
------------------------------|-----------------------------------
* Series.order() | Series.sort_values()
* Series.sort() | Series.sort_values(inplace=True)
* DataFrame.sort(columns=...) | DataFrame.sort_values(by=...)