Q. Write a program to sort the values of a Series object s1 in ascending order of its values and store it into series object s2.


Answer :-


import pandas as pd
s1 = pd. Series (data = [200, 100, 500, 300, 400], index= ['I', 'K', 'J', 'L', 'M'])
s2 = s1.sort_values()
print("Series object s1:")
print (s1)
print("Series object s2:")
print(s2)


Output :-

Series object s1:
I    200
K    100
J    500
L    300
M    400
dtype: int64
Series object s2:
K    100
I    200
L    300
M    400
J    500
dtype: int64

>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post