Hi I have two data frames namely sales and cost
**SALES**
Sku Product qty_sold
0 A 4
0 A 3
0 A 1
1 B 6
1 B 2
2 C 1
2 C 1
**COST**
SKU Product qty_recieved Cost_price Batch
0 A 6 24 ABC
0 A 10 23.47 XYZ
1 B 10 30 AC1
1 B 2 28 AC1
2 C 50 24 AC2
I want to implement First In First Out (FIFO) method, for example for SKU 0 first we received 6 qty so I want to run a loop in sales['qty_sold'], for first 6 items sold I want to add new column depicting the cost price of that specific batch and as soon the first 6 items are sold, the loop will continue but for second row in cost[qty_recieved'] table i.e for 10.
I have tried every method but due to different number of columns and rows in both data frames I always get an error or the loop is not iterated for required number of times.
sales enter image description here cost enter image description here