Pandas group by on groupby to list of lists

后端 未结 1 2105
闹比i
闹比i 2021-02-19 06:11

Given a dataframe structured like:

rule_id | ordering | sequence_id
   1    |    0     |     12     
   1    |    1     |     13
   1    |    1     |     14
   2         


        
1条回答
  •  暖寄归人
    2021-02-19 06:16

    Use another groupby by first level of MultiIndex:

    df.groupby(['rule_id', 'ordering'])['sequence_id'].apply(list).groupby(level=0).apply(list)
    

    0 讨论(0)
提交回复
热议问题