I'm looking for pandas/python solution to summarize/group items in an invoice, based on it's main code. please refer the first attached image
each item value (price X qty) which has a MainCode should be added to the the item # total. Look for the Similar color. (Please Note some items may be repeated. eg : Green & Blue ) Qty SHOULD NOT be added. only the Values.
The answer should be as as follows
I'm New to Pandas & Since This is a bit Advanced problem, I couldn't come up with any code. hence, posted here. please direct me to solve this...
Things to note
- Item combination can be repeated. eg see Green & Blue
- Once Done Sub items should be removed (eg item # 371 is removed).
- totalamt should equal to the total of individual item's price X Qty
- In this example all sub item codes are 371. but it may have several codes. eg 371, 58, etc
- Sub Item 371 can be sold separately without a MainCode. In that case, it should not be allocated & it should remain.