Home > database >  How subtract group columns values in python pandas?
How subtract group columns values in python pandas?

Time:09-14

products.groupby(["Product Category"])[["Product Cost","Selling Cost"]].sum()

How to find Selling Margin?

CodePudding user response:

You can use assign to refer to a column in a chain

(products
.groupby(["Product Category"])[["Product Cost","Selling Cost"]]
.sum()
.assign(margin = lambda x: x['Selling Cost'] - x['Product Cost']))
  • Related