Q. Write a program to create data series and then change the indexes of the Series object in any random order.
Answer :-
import pandas as pd import numpy as np s1 = pd. Series (data = [100, 200, 300, 400, 500], index= ['I', 'J', 'K', 'L', 'M']) print("Original Data Series:") print (s1) s1 = s1.reindex (index = ['K', 'I', 'M', 'L', 'J']) print("Data Series after changing the order of index:") print(s1)
Output :-
Original Data Series:
I 100
J 200
K 300
L 400
M 500
dtype: int64
Data Series after changing the order of index:
K 300
I 100
M 500
L 400
J 200
dtype: int64
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )