Python Practice › Pandas Programs › Program 17

Reorder the index

EasyPandas Programs · 17 of 95

Write a pandas program to change the order of a Series’ index.

Advertisement
Input
["Sqa", "tools", "Learning", "python", "Is", "fun"]
Output
2    Learning
3      python
0         Sqa
1       tools
4          Is
5         fun
dtype: str

Approach

  1. reindex with the new order.

Solution

Python
import pandas as pds = pd.Series(["Sqa", "tools", "Learning", "python", "Is", "fun"])print(s.reindex([2, 3, 0, 1, 4, 5]))
Output
2    Learning
3      python
0         Sqa
1       tools
4          Is
5         fun
dtype: str

Learn the concept

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

More pandas programs

← All 95 Pandas Programs

Leave a Comment