Error in groupby sum
Hi I am finding a sum value of a column with a groupby function. my data is as follow:
gsm_id Team_SR Match_state Time_diff
2462796 Burnley Winning 0 days 00:23:15.000000000
2462796 Chelsea Losing 0 days 00:23:15.000000000
2462796 Burnley Winning 0 days 00:15:20.000000000
2462796 Chelsea Losing 0 days 00:15:20.000000000
2462796 Burnley Winning 0 days 00:03:34.000000000
2462796 Chelsea Losing 0 days 00:03:34.000000000
2462796 Chelsea Losing 0 days 00:25:59.000000000
2462796 Burnley Winning 0 days 00:25:59.000000000
2462796 Chelsea Losing 0 days 00:19:11.000000000
2462796 Burnley Winning 0 days 00:19:11.000000000
2462795 Manchester Winning 0 days 01:09:15.000000000
2462795 Brighton Losing 0 days 01:09:15.000000000
2462795 Manchester Winning 0 days 00:05:21.000000000
2462795 Brighton Losing 0 days 00:05:21.000000000
I used the following calculation and it gave me error:
Final_data['Losing_duration'] = Final_data.groupby(['gsm_id','Team_SR','Match_state'])['Time_diff'].sum()
The error is TypeError: incompatible index of inserted column with frame index
1 answer

I got it sorted by using transform fucntion:
Final_data['Losing_duration'] = Final_data.groupby(['gsm_id','Team_SR','Match_state'])['Time_diff'].transform('sum')