有沒有一種方法可以根據我的個人偏好重新排列熊貓數據框中的列(即不按字母順序或數字排序,但更像是遵循某些約定)?在熊貓數據框中設置列的順序
簡單的例子:
frame = pd.DataFrame({
'one thing':[1,2,3,4],
'second thing':[0.1,0.2,1,2],
'other thing':['a','e','i','o']})
產生這樣的:
one thing other thing second thing
0 1 a 0.1
1 2 e 0.2
2 3 i 1.0
3 4 o 2.0
但是,相反,我想這樣的:
one thing second thing other thing
0 1 0.1 a
1 2 0.2 e
2 3 1.0 i
3 4 2.0 o
(請提供一個通用的解決方案,而不是具體到這種情況非常感謝。)