Reputation: 3
I have a list of orders. Every order has a order-number (1, 2, 3, 4...). If a customer ordered more then 1 Item, the order-number will be the same.
Now I'd like to sumarize the prices oft the Items in a new column if the order number is the same. Is there a way to do that?
Thank you very much for your help!
Upvotes: 0
Views: 1352
Reputation: 30032
You can use transform('sum')
on grouped by, which will return a Series with the same index as the original dataframe. Sum value of each group is assigned to each group index.
df['sum'] = df.groupby('Order')['Price'].transform('sum')
Upvotes: 2