1# create a dataframe
2df = pd.DataFrame({'B':[1,2],'A':[0,0],'C':[1,1]})
3# reorder columns as ['A','B','C']
4df = df.reindex(columns = ['A','B','C'])
1cols = df.columns.tolist()
2cols = cols[-1:] + cols[:-1] #bring last element to 1st position
3df = df.reindex(cols, axis=1)
1In [7]: cols = df.columns.tolist()
2In [8]: cols
3Out[8]: [0L, 1L, 2L, 3L, 4L, 'mean']
4
5In [12]: cols = cols[-1:] + cols[:-1]
6
7In [13]: cols
8Out[13]: ['mean', 0L, 1L, 2L, 3L, 4L]
9
10In [14]: df = df[cols]
1# Want to change column3 to show up first
2df = pd.Dataframe({
3 "column1":(1,2,3),
4 "column2":(4,5,6),
5 "column3":(7,8,9)
6}
7# From all solutions I could find, this seems to be the best performance wise:
8col = df.pop(col_name)
9df.insert(0, col.name, col)# <- works in place and returns None (at least for me)
10
11