Python Forum
How to sort values descending from a row in a dataframe using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to sort values descending from a row in a dataframe using python
#1
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.

Attached Files

.csv   SAMPLE.csv (Size: 150 bytes / Downloads: 258)
Reply
#2
(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
while dad_has_cigs == True:
    happiness = True
    if dad_has_cigs == False:
    print("Dad come home!")
    happiness = not happiness
    break
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Transposing a dataframe without creating NaN values doug2019 2 996 Mar-18-2023, 03:14 PM
Last Post: jefsummers
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,328 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  List of dataframe values beginning with x,y or z glidecode 3 1,950 Nov-08-2021, 10:16 PM
Last Post: glidecode
  How to get value in Dataframe given row & column values? moonlight 1 2,439 Apr-26-2021, 09:30 PM
Last Post: Larz60+
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,514 Mar-09-2021, 12:24 PM
Last Post: KMV
  Dataframe extract key values danipyth 0 1,671 Feb-07-2021, 03:52 PM
Last Post: danipyth
  python sort date beginner2020 13 6,087 Nov-06-2020, 03:30 PM
Last Post: beginner2020
  Assigning Column nunique values to another DataFrame column Pythonito 1 1,889 Jun-26-2020, 06:52 AM
Last Post: hussainmujtaba
  What's the best way to sort this data with Python? xtrax 2 1,702 Mar-15-2020, 08:08 AM
Last Post: Larz60+
  complex sort in dataframe gjs_2020 0 1,471 Feb-07-2020, 02:10 PM
Last Post: gjs_2020

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020