Python Practice › Pandas Programs › Program 14
Sort a Series
Write a pandas program to sort a Series.
Input
[55, 23, 10, 87]
Output
2 10 1 23 0 55 3 87 dtype: int64
Approach
sort_values().
Solution
import pandas as pdprint(pd.Series([55, 23, 10, 87]).sort_values())Output
2 10 1 23 0 55 3 87 dtype: int64
Line by line
Line 2
The index labels move with their values.
Learn the concept
New to this topic? Read the lesson, then come back.