import numpy as np
import pandas as pd
df = pd.DataFrame(data={'result':[-6.77,6.11,5.67,-7.679,-0.0930,4.342]}\
,index=['A','B','C','D','E','F'])
new_order = np.array([1,2,2,0,1,0])
The num_ array new_orderassigns each row one of three groups [0,1 or 2]. I would like to change the lines dfso that first lines appear in group 0, then 1, and finally 2. In each of the three groups, the initial ordering should remain unchanged.
At the beginning, df is organized as follows:
result
A -6.770
B 6.110
C 5.670
D -7.679
E -0.093
F 4.342
Here is the desired result, given the above input.
result
D -7.679
F 4.342
A -6.770
E -0.093
B 6.110
C 5.670
source
share