4.11. Series Sort
4.11.1. SetUp
>>> import pandas as pd
>>>
>>>
>>> s = pd.Series(
... data = [99.9, 3.14, -5.99, 0.0, 77.1],
... index = [0, 99, 6, -4, 2])
>>>
>>> s
0 99.90
99 3.14
6 -5.99
-4 0.00
2 77.10
dtype: float64
4.11.2. Sort Values
Series.sort_values(ascending=True) - Sorts the values of the Series in ascending order.
>>> s.sort_values()
6 -5.99
-4 0.00
99 3.14
2 77.10
0 99.90
dtype: float64
>>> s.sort_values(ascending=False)
0 99.90
2 77.10
99 3.14
-4 0.00
6 -5.99
dtype: float64
4.11.3. Sort Index
Series.sort_index(ascending=True) - Sorts the index of the Series in ascending order.
>>> s.sort_index()
-4 0.00
0 99.90
2 77.10
6 -5.99
99 3.14
dtype: float64
>>> s.sort_index(ascending=False)
99 3.14
6 -5.99
2 77.10
0 99.90
-4 0.00
dtype: float64