Back

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

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

['Q1.3','Q6.1','Q1.2','Q1.1',......]

I need to re-order the columns as follows:

['Q1.1','Q1.2','Q1.3',.....'Q6.1',......]

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

...