I have the following DataFrame (df):
DataFrame
df
import numpy as np import pandas as pd df = pd.DataFrame(np.random.rand(10, 5))
This question has been answered before but reindex_axis is deprecated now so I would suggest to use:
df.reindex(sorted(df.columns), axis=1)