Turning values into columns

Another way:

df = pd.DataFrame({
    'A': [1, 3, 2, 1, 2],
    'B': [2, 1, 3, 2, 3],
    'C': [3, 2, 1, 2, 1],
})

(df.stack()
   .reset_index()
   .groupby(['level_0',0])
   .level_1.apply(''.join)
   .unstack()
)

Output:

0        1   2    3
level_0            
0        A   B    C
1        B   C    A
2        C   A    B
3        A  BC  NaN
4        C   A    B

here is one way stack

df.stack().reset_index(level=1).set_index(0,append=True)['level_1'].unstack()
Out[89]: 
0  1  2  3
0  A  B  C
1  B  C  A
2  C  A  B
3  A  B  C
4  C  A  B

You can use argsort:

pd.DataFrame(df.columns.values[np.argsort(df.values)])

   0  1  2
0  A  B  C
1  B  C  A
2  C  A  B
3  A  B  C
4  C  A  B