How to change the order of DataFrame columns?

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

    Here's a way to move one existing column that will modify the existing data frame in place.

    my_column = df.pop('column name')
    df.insert(3, my_column.name, my_column)
    

提交回复
热议问题