0

i have tried to make this df to the on after the line What i have

   Name    Id  Value_X  Value_Y   
0   Alex   34  1.1    2.5   
1   Julo   26  1.7    2.4   
2   Alex   34  0.9    0.5

pd.pivot_table(df, index=['Name','Id'],values=['Value_X','Value_Y'],aggfunc='sum')

But what i want:

   Name    Id  Value_X  Value_Y   
0   Alex   34  2.0    3.0   
1   Julo   26  1.7    2.4 

I used .groupby() but it always adds on Index the Name and the Id ('Alex','Id') but i want the dataframe without modifications on its columns.

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
castel594
  • 43
  • 4

2 Answers2

1

you need reset_index() along with groupby

df.groupby(['Name','Id'])['Value_X','Value_Y'].sum().reset_index()

or as_index=False

df.groupby(['Name','Id'],as_index = False)['Value_X','Value_Y'].sum()
M_S_N
  • 2,764
  • 1
  • 17
  • 38
0

You could try this way: if you want the columns of your choice

df.groupby(['Name','Age'])['Value_X','Value_Y'].sum()
Shubham Shaswat
  • 1,250
  • 9
  • 14