这个问题在这里已有答案:
对于给定的数据框:
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
如果我想要以下顺序,我怎么能手动重新排列我想要的列?
testc, testd, testa, testb
因此表格和情节将以这种方式:
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
您可以使用:
df = df.reindex_axis(['testc','testd', 'testa','testb'], axis=1)