Python Practice › Pandas Programs › Program 14

Sort a Series

EasyPandas Programs · 14 of 95

Write a pandas program to sort a Series.

Advertisement
Input
[55, 23, 10, 87]
Output
2    10
1    23
0    55
3    87
dtype: int64

Approach

  1. sort_values().

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs