I have two dataframes that look like this:
df1:
| item| order | qty_ordered |
|-----|-------|-------------|
| 1 | a1 | 5 |
| 1 | a2 | 7 |
| 2 | a3 | 10 |
| 2 | a4 | 8 |
df2:
| item| on_hand|
|-----|--------|
| 1 | 26 |
| 2 | 12 |
I need to take the qty_ordered for each item and subtract sequentially them from the on_hand value.
So desired output would be:
| item| order | qty_ordered | net |
|-----|-------|-------------|-----|
| 1 | a1 | 5 | 21 |
| 1 | a2 | 7 | 14 |
| 2 | a3 | 10 | 2 |
| 2 | a4 | 8 | -6 |
I have tried a few different options with .rolling() and .groupby(item) .diff() but no luck.
Any help would be greatly appreciated!