-2

I had a dataset as a result of groupby as :

CUSTID TRANSACTION_ID COUNT

CU_1    TR_1                1  
CU_1    TR_2                1
CU_1    TR_3                1
CU_2    TR_4                1  
CU_2    TR_5                1

I needed to have result as CUSTID TOTAL_COUNT

CU_1       3          
CU_2       2
David Erickson
  • 16,433
  • 2
  • 19
  • 35

1 Answers1

0

Run just:

df.groupby('CUSTID').COUNT.sum()

You need to group by a single column (CUSTID) only, then, from each group, take COUNT column and compute its sum().

Additional step may be to provide the required name to the resulting Series. If it is important, append .rename('TOTAL_COUNT') to the above code.

Yet another step may be to convert this Series into a DataFrame. To do it, append .to_frame() to the above code.

Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41