Categories
Python Answers

How to change the order of Python Pandas DataFrame columns?

Spread the love

To change the order of Python Pandas DataFrame columns, we can pyut the columns in a different order in a brackets.

For instance, we write

df = df[['mean', '0', '1', '2', '3']]

to add an array with the column names we want in the brackets to reorder them as listed.

And then we reassign the returned dataframe to df.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *