I have a dataframe with the following (code, inbound, sell) and I want to add (inventory, oh_avg), like that:
idx product inbound sell inventory oh_avg
1 1 6 3 3 1 (3/mean(3))
2 1 4 6 1 0.22 (1/mean(3+6))
3 1 4 0 5 1.67 (5/mean(3+6+0))
4 2 20 10 10 1 (10/mean(10))
5 2 10 5 15 2 (15/mean(10+5))
Inventory should be (inbound - sell + previous inventory)
oh_avg should be (inventory/mean(all previous sales))
Both should be by product
How do I do that?