How to sort data frame by column values?
<p>I am relatively new to python and pandas data frames so maybe I have missed something very easy here.
So I was having data frame with many rows and columns but at the end finally manage to get only one row with maximum value from each column. I used this code to do that:</p>

<pre><code>import pandas as pd

d = {'A' : [1.2, 2, 4, 6],
     'B' : [2, 8, 10, 12],
     'C' : [5, 3, 4, 5],
     'D' : [3.5, 9, 1, 11],
     'E' : [5, 8, 7.5, 3],
     'F' : [8.8, 4, 3, 2]}


df = pd.DataFrame(d, index=['a', 'b', 'c', 'd'])
print df

Out:
     A   B  C     D    E    F
a  1.2   2  5   3.5  5.0  8.8
b  2.0   8  3   9.0  8.0  4.0
c  4.0  10  4   1.0  7.5  3.0
d  6.0  12  5  11.0  3.0  2.0
</code></pre>

<p>Then to choose max value from each column I used this function:</p>

<pre><code>def sorted(s, num):
    tmp = s.order(ascending=False)[:num]
    tmp.index = range(num)
    return tmp

NewDF=df.apply(lambda x: sorted(x, 1))
print NewDF

Out:
     A   B  C     D    E    F
0  6.0  12  5  11.0  8.0  8.8
</code></pre>

<p>Yes, I lost row labels (indexes whatever) but this column labels are more important for me to retain. Now I just need to sort columns I need top 5 columns based on values inside them, I need this output:</p>

<pre><code>Out:
   B     D   F    E    A    
0  12.0  11  8.8  8.0  6.0
</code></pre>

<p>I was looking for a solution but with no luck. The best I found for sorting by columns is print NewDF.sort(axis=1) but nothing happens.</p>

<p>Edit:
Ok, I found one way but with transformation:</p>

<pre><code>transposed = NewDF.T
print(transposed.sort([0], ascending=False))
</code></pre>

<p>Is this the only possible way to do it?</p>