Python Practice › Pandas Programs › Program 17
Reorder the index
Write a pandas program to change the order of a Series’ index.
Input
["Sqa", "tools", "Learning", "python", "Is", "fun"]
Output
2 Learning 3 python 0 Sqa 1 tools 4 Is 5 fun dtype: str
Approach
reindexwith the new order.
Solution
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.