Write a program in Python to sort all the elements in a given series in descending order


Input − Assume, you have a Series,

0 abdef
1 ijkl
2 Abdef
3 oUijl

Output − And the result for all the elements in descending order,

3 oUijl
1 ijkl
0 abdef
2 Abdef

Solution

To solve this, we will follow the steps given below −

  • Define a Series

  • Apply sort_values method with the argument as ascending = False. It is defined below,

data.sort_values(ascending=False)

Example

The complete code listing is as follows,

import pandas as pd
l=["abdef","ijkl","Abdef","oUijl"]
data=pd.Series(l)
print("original series: \n ", data)
print(data.sort_values(ascending=False))

Output

3    oUijl
1    ijkl
0    abdef
2    Abdef

Updated on: 24-Feb-2021

113 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements