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']))