MultiIndex.
sort_values
Return a sorted copy of the index.
Note
This method is not supported for pandas when index has NaN value. pandas raises unexpected TypeError, but we support treating NaN as the smallest value.
Should the index values be sorted in an ascending order.
Sorted copy of the index.
See also
Series.sort_values
Sort values of a Series.
DataFrame.sort_values
Sort values in a DataFrame.
Examples
>>> idx = ps.Index([10, 100, 1, 1000]) >>> idx Int64Index([10, 100, 1, 1000], dtype='int64')
Sort values in ascending order (default behavior).
>>> idx.sort_values() Int64Index([1, 10, 100, 1000], dtype='int64')
Sort values in descending order.
>>> idx.sort_values(ascending=False) Int64Index([1000, 100, 10, 1], dtype='int64')
Support for MultiIndex.
>>> psidx = ps.MultiIndex.from_tuples([('a', 'x', 1), ('c', 'y', 2), ('b', 'z', 3)]) >>> psidx MultiIndex([('a', 'x', 1), ('c', 'y', 2), ('b', 'z', 3)], )
>>> psidx.sort_values() MultiIndex([('a', 'x', 1), ('b', 'z', 3), ('c', 'y', 2)], )
>>> psidx.sort_values(ascending=False) MultiIndex([('c', 'y', 2), ('b', 'z', 3), ('a', 'x', 1)], )