- Using the loc indexer, you can pass a column sequence list to the loc indexer to rearrange the column order. For example: df=df[['col3','col2','col1']], which places the col3 column in the first column, the col2 column in the second column, and the col1 column in the third column.
- Use loc integer position selector, df=df.iloc[:,[2,1,0]]
- Use the take method, df=df.take([2,1,0],axis=1)
- Directly reassign the columns attribute, such as df=df[['col3','col2','col1']], df.columns=['col3','col2','col1'], etc.
pandas adjust file column order
Guess you like
Origin blog.csdn.net/Darin2017/article/details/132066943
Recommended
Ranking