How to change the order of DataFrame columns?

前端 未结 30 1576
南旧
南旧 2020-11-22 01:24

I have the following DataFrame (df):

import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.rand(10, 5))
30条回答
  •  名媛妹妹
    2020-11-22 02:03

    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)
    

提交回复
热议问题