The behavior of these methods differs in confusing ways:
DF:
- DataFrame.sort_index
takes a by
parameter, in which case the index is resorted by a specific column's values
- DataFrame.sort
defaults to inplace=False
- DataFrame.order
does not exist
Series:
- Series.sort
defaults to inplace=True
- Series.order
defaults to inplace=False
, but is otherwise identical to Series.sort
- Series.sort_index
does not take a by
parameter
This makes it very hard to remember which one to use, especially after an aggregating function. For example:
df.max(axis=1).order(ascending=False) # max returns a Series in this case, use Series methods
df.max(level='Foo').sort_index(by='Bar') # max returns a DF in this case, use DF methods
Any reason not to make the inplace
behavior identical for DataFrame.sort
and Series.sort
? Also, Series.sort_index
could take by=0
to replicate the behavior of DataFrame
.
Comment From: jreback
see #9816 and others for discussion