I currently have a data set where im trying to group up rows based on a column and sum the columns where the values are integers.
However, the catch is I would like to create a new row once the sum has reached a certain threshhold
For example, in the below dataframe, I am trying to group the rows based on company name and sum up the weights, however, I do not want weight to exceed 100.
Input dataframe:
Company | Weight |
---|---|
a | 30 |
b | 45 |
a | 27 |
a | 40 |
b | 57 |
a | 57 |
b | 32 |
Output dataframe:
Company | Weight |
---|---|
a | 97 |
a | 57 |
b | 89 |
b | 45 |
I have tried using group by and sum, however, it cannot detect whether or not I have reached a maximum amount.
Is there any way I can achieve this?
Any help would be greatly appreciated!