Given a dataframe structured like:
rule_id | ordering | sequence_id 1 | 0 | 12 1 | 1 | 13 1 | 1 | 14 2
Use another groupby by first level of MultiIndex:
groupby
MultiIndex
df.groupby(['rule_id', 'ordering'])['sequence_id'].apply(list).groupby(level=0).apply(list)