I'm looking for a method to sort a dataframe by a column which consists of arrays. Below is my dataframe with index, arrays(a) and values (b).
index a b
0 [0] 0.014066
1 [1] 0.569054
2 [2] 0.379795
3 [3] 0.037084
4 [4] 0.699488
5 [5] 0.191816
6 [6] 0.107417
7 [0, 4] 0.008951
8 [0, 5] 0.002558
9 [0, 6] 0.002558
10 [1, 4] 0.448849
11 [1, 5] 0.089514
12 [1, 6] 0.030691
13 [2, 4] 0.217391
14 [2, 5] 0.095908
15 [2, 6] 0.066496
16 [3, 4] 0.024297
17 [3, 5] 0.003836
18 [3, 6] 0.007673
19 [0, 3] 0.000000
20 [1, 3] 0.000000
21 [2, 3] 0.000000
As seen the last 3 arrays are not sorted like the others. What I would like would be this:
index a b
0 [0] 0.014066
1 [1] 0.569054
2 [2] 0.379795
3 [3] 0.037084
4 [4] 0.699488
5 [5] 0.191816
6 [6] 0.107417
-> [0,3] here
7 [0, 4] 0.008951
8 [0, 5] 0.002558
9 [0, 6] 0.002558
-> [1,3] here
10 [1, 4] 0.448849
11 [1, 5] 0.089514
12 [1, 6] 0.030691
-> [2,3] here
13 [2, 4] 0.217391
14 [2, 5] 0.095908
15 [2, 6] 0.066496
16 [3, 4] 0.024297
17 [3, 5] 0.003836
18 [3, 6] 0.007673
Hope that makes sense. Thanks in advance! df.sort_values('a') doesn't seem to work. Only on the values in b.