hello I wanted to ask a similar question answered here: Pandas group-by and sum
I could not comment my question in that link as i had less than 50 reputation.
That's why I am asking here: I wanted to achieve the same result as the one asked in the link above. But in my case I want to get the sum of last n columns after group by.
I have something like this:
A B C D E F G H I J K L
0 2 5 4 3 2 1 8 5 6 3 3
0 2 8 6 5 2 4 6 2 4 5 2
0 2 5 6 4 5 6 6 6 6 6 8
1 5 6 5 6 5 6 5 6 8 5 2
1 5 7 6 5 4 6 3 8 5 2 2
1 5 4 5 6 3 2 1 4 5 6 9
This is what I tried:
df.groupby(['A', 'B'])[['C','D','E','F','G','H','I','J']].agg('sum')
But I suppose it is not possible when there is close to 50 columns Is there any way I can select the last n number of columns after groupby and take sum?