pandas dataframe sort columns according to column totals

nealous3

I was able to sort rows according to the last column. However, I also have a row at the bottom of the dataframe which has the totals of each column. I couldn't find a way to sort the columns according to the totals in the last row. The table looks like the following:

   A  B  C  T
0  9  9  9  27
1  9  10 4  23
2  7  4  8  19
3  2  6  9  17
T  27 29 30

I want this table to be sorted so that the order of columns will be from left to right C, B, A from highest total to lowest. How can this be done?

jezrael

Use DataFrame.sort_values by index value T with axis=1:

df = df.sort_values('T', axis=1, ascending=False)
print (df)
    C   B   A     T
0   9   9   9  27.0
1   4  10   9  23.0
2   8   4   7  19.0
3   9   6   2  17.0
T  30  29  27   NaN

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Sort pandas DataFrame with MultiIndex according to column value

From Dev

Sort dates in a DataFrame according to column keeping other columns' values using Pandas

From Dev

Sort pandas dataframe rows according to a string value column

From Dev

Convert timezone of multiple columns in a pandas DataFrame according to a third column?

From Python

Create columns for Pandas Dataframe according to value of other column

From Dev

Sort dataframe rows according to values in specific columns

From Dev

Pandas: How to sort dataframe on columns with same column labels

From Dev

Sort a subset of columns of a pandas dataframe alphabetically by column name

From Dev

Pandas Dataframe sort by a column

From Dev

Sort dataframe column according to another dataframe's column

From Python

sort pandas dataframe by sum of columns

From Python

sort pandas dataframe by sum of columns

From Dev

Updating pandas DataFrame according to columns not index

From Dev

Pandas - split dataframe according to sorted sequence in columns

From Dev

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

From Python

Split Pandas Dataframe Column According To a Value

From Python

Subsetting a dataframe in pandas according to column name values

From Dev

Changing a pandas dataframe column value according to conditions

From Dev

How to combine Pandas dataframe according to unique column

From Dev

Reordering index column according to date in Pandas dataframe

From Java

Sort Pandas Dataframe by substrings of a column

From Dev

Sort lists in a Pandas Dataframe column

From Dev

Sort dataframe by first column, Pandas

From Dev

Pandas DataFrame Sort every Column

From Dev

sort pandas DataFrame with a column with list

From Dev

how to sort a dataframe according to another dataframe column values?

From Dev

sort particular column values according to specific column python dataframe

From Dev

How to sum up the columns of a pandas dataframe according to the elements in one of the columns

From Dev

Sort blocks of columns according to specific column value in R

Related Related

  1. 1

    Sort pandas DataFrame with MultiIndex according to column value

  2. 2

    Sort dates in a DataFrame according to column keeping other columns' values using Pandas

  3. 3

    Sort pandas dataframe rows according to a string value column

  4. 4

    Convert timezone of multiple columns in a pandas DataFrame according to a third column?

  5. 5

    Create columns for Pandas Dataframe according to value of other column

  6. 6

    Sort dataframe rows according to values in specific columns

  7. 7

    Pandas: How to sort dataframe on columns with same column labels

  8. 8

    Sort a subset of columns of a pandas dataframe alphabetically by column name

  9. 9

    Pandas Dataframe sort by a column

  10. 10

    Sort dataframe column according to another dataframe's column

  11. 11

    sort pandas dataframe by sum of columns

  12. 12

    sort pandas dataframe by sum of columns

  13. 13

    Updating pandas DataFrame according to columns not index

  14. 14

    Pandas - split dataframe according to sorted sequence in columns

  15. 15

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

  16. 16

    Split Pandas Dataframe Column According To a Value

  17. 17

    Subsetting a dataframe in pandas according to column name values

  18. 18

    Changing a pandas dataframe column value according to conditions

  19. 19

    How to combine Pandas dataframe according to unique column

  20. 20

    Reordering index column according to date in Pandas dataframe

  21. 21

    Sort Pandas Dataframe by substrings of a column

  22. 22

    Sort lists in a Pandas Dataframe column

  23. 23

    Sort dataframe by first column, Pandas

  24. 24

    Pandas DataFrame Sort every Column

  25. 25

    sort pandas DataFrame with a column with list

  26. 26

    how to sort a dataframe according to another dataframe column values?

  27. 27

    sort particular column values according to specific column python dataframe

  28. 28

    How to sum up the columns of a pandas dataframe according to the elements in one of the columns

  29. 29

    Sort blocks of columns according to specific column value in R

HotTag

Archive