How to change the order of DataFrame columns?

前端 未结 30 2002
南旧
南旧 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:28

    I think this is a slightly neater solution:

    df.insert(0,'mean', df.pop("mean"))
    

    This solution is somewhat similar to @JoeHeffer 's solution but this is one liner.

    Here we remove the column "mean" from the dataframe and attach it to index 0 with the same column name.

提交回复
热议问题