df = pd.DataFrame({
'from': ['Start', '21', '73', 'Start', '55', '1', '2', '3'],
'to': ['21', '73', '55', '1', '54', '2', '3', '4']
})
from | to | |
---|---|---|
0 | Start | 21 |
1 | 21 | 73 |
2 | 73 | 55 |
3 | Start | 1 |
4 | 55 | 54 |
5 | 1 | 2 |
6 | 2 | 3 |
7 | 3 | 4 |
desired output
[['Start', '21', '73', '55', '54'], ['Start', '1', '2', '3', '4']]
the rows don’t have to be in the correct order, as for 55, 54.