20

For a given data frame:

UUT                  testa  testb  testc  testd
DateTime                                
2017-11-21 18:47:29    1.0    1.0    1.0    3.0
2017-11-21 18:47:30    1.0    2.0    1.0    4.0
2017-11-21 18:47:31    1.0    2.0    5.0    2.0
2017-11-21 18:47:32    1.0    2.0    5.0    1.0
2017-11-21 18:47:33    1.0    2.0    5.0    4.0
2017-11-21 18:47:34    1.0    2.0    5.0    1.0

how can I manually rearrange the columns anyway I want it for example if I want to the following sequence:

testc, testd, testa, testb

So the table and the plot will be in this way:

UUT                  testc  testd  testa  testb  
DateTime                                         
2017-11-21 18:47:29    1.0    3.0    1.0    1.0  
2017-11-21 18:47:30    1.0    4.0    1.0    2.0  
2017-11-21 18:47:31    5.0    2.0    1.0    2.0  
2017-11-21 18:47:32    5.0    1.0    1.0    2.0  
2017-11-21 18:47:33    5.0    4.0    1.0    2.0  
2017-11-21 18:47:34    5.0    1.0    1.0    2.0
user97662
  • 942
  • 1
  • 10
  • 29
  • https://stackoverflow.com/questions/13148429/how-to-change-the-order-of-dataframe-columns – Sruthi Dec 19 '17 at 08:12
  • There is an answer for you right here : https://stackoverflow.com/questions/13148429/how-to-change-the-order-of-dataframe-columns – Yoann boyere Dec 19 '17 at 08:14

1 Answers1

12

You can use:

df = df.reindex_axis(['testc','testd', 'testa','testb'], axis=1)
Joe
  • 12,057
  • 5
  • 39
  • 55