Q. Write a program to sort the values of a Series object s1 in descending order of its indexes and store it into series object s3.
Answer :-
import pandas as pd s1 = pd. Series (data = [200, 100, 500, 300, 400], index= ['I', 'K', 'J', 'L', 'M']) s3 = s1.sort_index (ascending = False) print("Series object s1:") print (s1) print ("Series object s3:") print (s3)
Output :-
Series object s1:
I 200
K 100
J 500
L 300
M 400
dtype: int64
Series object s3:
M 400
L 300
K 100
J 500
I 200
dtype: int64
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )