I have three data sources:
Sales Forecast - This is future forecasted sales for products:
| Product | Forecast_Quantity | Forecast_Month |
|---|---|---|
| Product A | 5 | 2021-02-28 |
| Product B | 6 | 2021-02-28 |
| Product C | 2 | 2021-02-28 |
| Product A | 5 | 2021-03-31 |
| Product B | 6 | 2021-03-31 |
| Product C | 2 | 2021-03-31 |
| Product A | 5 | 2021-04-30 |
| Product B | 6 | 2021-04-30 |
| Product C | 2 | 2021-04-30 |
Planned Deliveries (Purchase Orders) - what is planned to be delivered in:
| Product | Delivery_Quantity | Delivery_Month |
|---|---|---|
| Product A | 2 | 2021-02-28 |
| Product B | 4 | 2021-02-28 |
| Product C | 5 | 2021-02-28 |
| Product A | 8 | 2021-03-31 |
| Product B | 2 | 2021-03-31 |
| Product C | 4 | 2021-03-31 |
| Product A | 2 | 2021-04-30 |
| Product B | 6 | 2021-04-30 |
| Product C | 3 | 2021-04-30 |
Current inventory - what is currently in stock:
| Product | Inventory_Quantity | Inventory_Month |
|---|---|---|
| Product A | 20 | 2021-01-31 |
| Product B | 16 | 2021-01-31 |
| Product C | 21 | 2021-01-31 |
I wish to create a small program that returns a dataframe projecting my future inventory for each product. It should take last months closing inventory add on the delivery quantity and take off the forecasted sales. Expected output:
| Product | Inventory_Quantity | Inventory_Month |
|---|---|---|
| Product A | 20 | 2021-01-31 |
| Product B | 16 | 2021-01-31 |
| Product C | 21 | 2021-01-31 |
| Product A | 17 | 2021-02-28 |
| Product B | 14 | 2021-02-28 |
| Product C | 24 | 2021-02-28 |
It would be for 18 months of data (but I've just used a 2 months of output for the above table).
I've have tried a few different approaches, such as trying cusum() or using a for loop but I don't my logic has been right.
This is the code I have so far that combines the forecast and deliveries into a 'net' figure:
import pandas as pd
import numpy as np
# Import CSV files as dataframe
fcs = pd.read_csv(r'forecast.csv')
inv = pd.read_csv(r'inventory.csv')
pos = pd.read_csv(r'purchase_orders.csv')
# Inner join to get a net position for each month (PO Qty - Fcs Qty)
net = pd.merge(pos, fcs, left_on=['SKU', 'Delivery_Date'], right_on=['SKU', 'Forecast_Date'])
# Create net
net['net'] = (net['PO_Quantity'] - net['Forecast_Quantity'])
I'm unsure on the best approach to now generate the new table that combines with the inventory?