Python Forum
How to sort values descending from a row in a dataframe using python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to sort values descending from a row in a dataframe using python (/thread-34632.html)



How to sort values descending from a row in a dataframe using python - sankarachari - Aug-15-2021

Hi There,
I would like to sort values descending to each row in a dataframe based grouping 1st col values.
Group col1 values and display relevant values of col1 in col2, col3 descending order.
I dont know how to do it. Can anyone sort values in descending order as shown in excel sheet?

Plz find the attached sheet.


RE: How to sort values descending from a row in a dataframe using python - jamesaarr - Aug-16-2021

(Aug-15-2021, 06:23 PM)sankarachari Wrote: Hi There,
I would like to sort values descending to each row in a dataframe based grouping 1st col values.
Group col1 values and display relevant values of col1 in col2, col3 descending order.
I dont know how to do it. Can anyone sort values in descending order as shown in excel sheet?

Plz find the attached sheet.

import numpy as np

def main():
    a = np.genfromtxt('file.csv',delimiter=",")
    b = np.sort(a)
This saves the csv to an array and then sorts it. If you're using pandas, maybe save each column to an array and use the numpy sort function, and then rebuild your dataframe after.

Cheers,
Jamie