You can also do more succinctly:
df.sort_index(axis=1)
df.sort_index(axis=1) Edit:
Make sure you holdassign the valueresult back:
df = df.sort_index(axis=1)
df = df.sort_index(axis=1) Or, do it in place-place:
df.sort_index(axis=1, inplace=True)
df.sort_index(axis=1, inplace=True)