row wise sorting in pandas dataframe and aggregation

后端 未结 1 1934
悲哀的现实
悲哀的现实 2021-01-25 22:29

I have a table in pandas dataframe df

col1    col2     count
12       15        3
13       17        5
1        36        4
15       12        7
36       1               


        
相关标签:
1条回答
  • 2021-01-25 22:35

    Sort your rows, then group and sum:

    df[['a', 'b']] = df[['a', 'b']].apply(sorted, axis=1)
    df.groupby(['a', 'b'], as_index=False)['c'].sum()
    
    0 讨论(0)
提交回复
热议问题