Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sorting single row dataframe by column values

I have to sort columns in single row dataframe by descending order.

dataframe looks like:

   store_1  store_2  store_3
0       11       54       28

result should be like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

   store_2  store_3  store_1
0       54       28       11

dataframe has more than sixty columns.

>Solution :

You can use the pandas.Series.sort_values:

import pandas as pd

df = pd.DataFrame(data=[[11,54,28]], columns=['store_1', 'store_2', 'store_3'])
df = df.sort_values(by=0, axis=1, ascending=False)
print(df)

output will be:

   store_2  store_3  store_1
0       54       28       11
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading