0 votes
1 view
in Python by (47.8k 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 (107k 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)

Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...