Sort dataframe by first column, Pandas

Carmen

I have a dataframe with one column, which I would like to sort. Typing following code gives me a sorted dataframe:

sort = tst.sort(["Mean"], ascending = False)

                Mean
SIMULATION          
Sim_758     1.351917
Sim_215     1.072942
Sim_830     0.921284
Sim_295     0.870272
Sim_213     0.845990
Sim_440     0.822394

This will be part of a function, which will be applied to other dataframes. For this reason I need to sort the dataframe without mentioning the column name "mean".

Is there a way to sort a dataframe by the values of a column, only indicating the position of the column?

jezrael

I think you can select first column by tst.columns[0], better is use sort_values because sort return warning:

FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)

sort = tst.sort_values(tst.columns[0], ascending = False)

print (tst)
                Mean
SIMULATION          
Sim_213     0.845990
Sim_758     1.351917
Sim_830     0.921284
Sim_295     0.870272
Sim_215     1.072942
Sim_830     0.921284
Sim_295     0.870272
Sim_440     0.822394

print (tst.columns[0])
Mean

sort = tst.sort_values(tst.columns[0], ascending = False)
print (sort)
                Mean
SIMULATION          
Sim_758     1.351917
Sim_215     1.072942
Sim_830     0.921284
Sim_830     0.921284
Sim_295     0.870272
Sim_295     0.870272
Sim_213     0.845990
Sim_440     0.822394

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pandas Dataframe sort by a column

From Dev

Sort a pandas DataFrame by a column in another dataframe - pandas

From Java

Sort Pandas Dataframe by substrings of a column

From Dev

Sort lists in a Pandas Dataframe column

From Dev

Pandas DataFrame Sort every Column

From Dev

sort pandas DataFrame with a column with list

From Dev

pandas sort column by ABSOLUTE correlation to first column

From Dev

Get Pandas DataFrame first column

From Dev

Inaccesable first column in pandas dataframe?

From Dev

Pandas Dataframe: Sort list column in dataframe

From Dev

Sort dataframe based on first digit of a column

From Dev

Sort pandas dataframe column based on substring

From Dev

Sort column in Pandas DataFrame by specific order

From Dev

sort and count values in a column DataFrame (Python Pandas)

From Java

Sort pandas DataFrame with MultiIndex according to column value

From Dev

Sort dataframe by another on one column - pandas

From Dev

pandas sort dataframe by column that includes numbers and letters

From Java

how to sort pandas dataframe from one column

From Dev

sort Pandas Dataframe based on column value

From Dev

Pandas: how to sort dataframe by column AND by index

From Dev

Sort by one column, then group by another, in Pandas Dataframe?

From Dev

pandas dataframe sort columns according to column totals

From Dev

pandas dataframe sort on column raises keyerror on index

From Dev

How to sort a Dataframe by the ocurrences in a column in Python (pandas)

From Dev

Sort rows and get column IDs in a pandas dataframe

From Dev

Is there a way to sort a pandas dataframe by column of numerical strings?

From Dev

Sort Pandas dataframe column index by date

From Dev

Sort pandas dataframe by column specifying custom order

From Dev

Sort a pandas dataframe by the second string in a column

Related Related

  1. 1

    Pandas Dataframe sort by a column

  2. 2

    Sort a pandas DataFrame by a column in another dataframe - pandas

  3. 3

    Sort Pandas Dataframe by substrings of a column

  4. 4

    Sort lists in a Pandas Dataframe column

  5. 5

    Pandas DataFrame Sort every Column

  6. 6

    sort pandas DataFrame with a column with list

  7. 7

    pandas sort column by ABSOLUTE correlation to first column

  8. 8

    Get Pandas DataFrame first column

  9. 9

    Inaccesable first column in pandas dataframe?

  10. 10

    Pandas Dataframe: Sort list column in dataframe

  11. 11

    Sort dataframe based on first digit of a column

  12. 12

    Sort pandas dataframe column based on substring

  13. 13

    Sort column in Pandas DataFrame by specific order

  14. 14

    sort and count values in a column DataFrame (Python Pandas)

  15. 15

    Sort pandas DataFrame with MultiIndex according to column value

  16. 16

    Sort dataframe by another on one column - pandas

  17. 17

    pandas sort dataframe by column that includes numbers and letters

  18. 18

    how to sort pandas dataframe from one column

  19. 19

    sort Pandas Dataframe based on column value

  20. 20

    Pandas: how to sort dataframe by column AND by index

  21. 21

    Sort by one column, then group by another, in Pandas Dataframe?

  22. 22

    pandas dataframe sort columns according to column totals

  23. 23

    pandas dataframe sort on column raises keyerror on index

  24. 24

    How to sort a Dataframe by the ocurrences in a column in Python (pandas)

  25. 25

    Sort rows and get column IDs in a pandas dataframe

  26. 26

    Is there a way to sort a pandas dataframe by column of numerical strings?

  27. 27

    Sort Pandas dataframe column index by date

  28. 28

    Sort pandas dataframe by column specifying custom order

  29. 29

    Sort a pandas dataframe by the second string in a column

HotTag

Archive