Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

I have a dataframe with over 200 columns. The issue is as they were generated the order is


I need to re-order the columns as follows:


Is there some way for me to do this within Python?

1 Answer

0 votes
by (106k points)

For Re-ordering columns in pandas dataframe based on a column name you can use the below-mentioned piece of code:-

df = df.reindex(sorted(df.columns), axis=1)

Browse Categories