0

I have a dataframe that looks like:

param1   param2   num1    num2
A          B        4      0.3
A          C        5      0.1
A          B        6      0.5
B          F        3      0.7
C          A        1      0.8
C          A        2      1.1

and I want something like

param1   param2   num1    num2
A          B        10     0.8
A          C        5      0.1
B          F        3      0.7
C          A        3      1.9

If I use something like: df.groupby(['param1', 'param2']).sum() I end up with the columns 'param1' and 'param2' fused as an index, but I don't want that. I just need them to stay as they are, but if I have some lines with the same param1 and param2, sum the 'nums' associated to them.

Aude
  • 368
  • 2
  • 13
  • 2
    Use `df.groupby(['param1', 'param2'], as_index=False).sum()` or `df.groupby(['param1', 'param2']).sum().reset_index()` – jezrael Sep 03 '21 at 09:00

1 Answers1

2

Use the as_index=False parameter:

df.groupby(['param1', 'param2'], as_index=False).sum()`
mozway
  • 81,317
  • 8
  • 19
  • 49