How do I order columns according to the values of the last row? In the example below, my final dataframe should have columns in the following order: 'ddd' 'aaa' 'ppp' 'fff'.

>>> df = DataFrame(np.random.randn(10, 4), columns=['ddd', 'fff', 'aaa', 'ppp'])
>>> df
        ddd       fff       aaa       ppp
0 -0.177438  0.102561 -1.318710  1.321252
1  0.980348  0.786721  0.374506 -1.411019
2  0.405112  0.514216  1.761983 -0.529482
3  1.659710 -1.017048 -0.737615 -0.388145
4 -0.472223  1.407655 -0.129119 -0.912974
5  1.221324 -0.656599  0.563152 -0.900710
6 -1.816420 -2.898094 -0.232047 -0.648904
7  2.793261  0.568760 -0.850100  0.654704
8 -2.180891  2.054178 -1.050897 -1.461458
9 -1.123756  1.245987 -0.239863  0.359759
Edit
Report