Skip to main content
added 17 characters in body
Source Link
cs95
  • 406.2k
  • 106
  • 744
  • 797

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) 

You can also do more succinctly:

df.sort_index(axis=1)

Edit:

Make sure you hold the value

df = df.sort_index(axis=1)

Or do it in place

df.sort_index(axis=1, inplace=True)

You can also do more succinctly:

df.sort_index(axis=1) 
 

Make sure you assign the result back:

df = df.sort_index(axis=1) 

Or, do it in-place:

df.sort_index(axis=1, inplace=True) 
add better approaches pointed out in comments.
Source Link

You can also do more succinctly:

df.sort_index(axis=1)

Edit:

Make sure you hold the value

df = df.sort_index(axis=1)

Or do it in place

df.sort_index(axis=1, inplace=True)

You can also do more succinctly:

df.sort_index(axis=1)

You can also do more succinctly:

df.sort_index(axis=1)

Edit:

Make sure you hold the value

df = df.sort_index(axis=1)

Or do it in place

df.sort_index(axis=1, inplace=True)

Source Link
Wes McKinney
  • 106.2k
  • 32
  • 146
  • 109

You can also do more succinctly:

df.sort_index(axis=1)