I have data similar to this.
data = [
dict(name = 'test1', index = '1' , status='fail'),
dict(name = 'test3', index = '3', status='pass'),
dict(name = 'test1', index = '11', status='pass'),
dict(name = 'test1', index = '1 2 14 56', status='fail'),
dict(name = 'test3', index = '20', status='fail'),
dict(name = 'test1', index = '2' , status='fail'),
dict(name = 'test3', index = '5:1:50', status='pass'),]
Note, that the type of the 'index' column is str. Since it has some irregular entries, I cannot easily convert this to a numeric type. (If this was possible I would not have this question.)
First I convert it into a DataFrame:
df = pd.DataFrame(data)
This gives me
name index status
0 test1 1 fail
1 test3 3 pass
2 test1 11 pass
3 test1 1 2 14 56 fail
4 test3 20 fail
5 test1 2 fail
6 test3 5:1:50 pass
Next I sort it:
df1 = df.sort_values(by=['name','index'])
Since the 'index' column is 'str', it will be sorted lexically.
name index status
0 test1 1 fail
3 test1 1 2 14 56 fail
2 test1 11 pass
5 test1 2 fail
4 test3 20 fail
1 test3 3 pass
6 test3 5:1:50 pass
What I actually want is this:
name index status
0 test1 1 fail
5 test1 2 fail
2 test1 11 pass
3 test1 1 2 14 56 fail
1 test3 3 pass
4 test3 20 fail
6 test3 5:1:50 pass
The irregular values in row numbers 4 and 7 (DF indices 3 and 6) could also go to the beginning of each test group. The key point is, that the values of the 'index' column, that could be converted to a numerical representation, shall be sorted numerically. And preferably in-place. How?