How to change the order of DataFrame columns?

前端 未结 30 2347
南旧
南旧 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

    A pretty straightforward solution that worked for me is to use .reindex on df.columns:

    df=df[df.columns.reindex(['mean',0,1,2,3,4])[0]]
    

提交回复
热议问题