Cheng Cheng - 1 year ago 288
Python Question

Pandas sort row values

I have a pandas dataframe like this:

Col1 Col2 Col3
1 1092 203 802

Is it possible to sort this dataframe and get a result like this:

Col1 Col3 Col2
1 1092 802 203

I tried
but it doesn't work. My work around is

Answer Source

Starting from 0.19.0, you could sort the columns based on row values.

df.sort_values(by=1, ascending=False, axis=1)

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download