pandas adjust file column order

  1. 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.
  2. Use loc integer position selector, df=df.iloc[:,[2,1,0]]
  3. Use the take method, df=df.take([2,1,0],axis=1)
  4. Directly reassign the columns attribute, such as df=df[['col3','col2','col1']], df.columns=['col3','col2','col1'], etc.

Guess you like

Origin blog.csdn.net/Darin2017/article/details/132066943