[英]Calculating difference of two data frames for each column of first data frame
[英]Compare same entry in two data frames in first column and move/add plus difference to the next column
我對生產中的所有機器有兩種不同的下載,我想根據可用容量預測生產量。 如需求較多,應順延至下一期,依此類推。 如果處理積壓,只應預測需求。 比如第一台機器第一個月產能不夠,所以從300的需求只能生產250-->把50移到下個月,所以下個月的需求是200+50但產能是220,所以預測應該是 220 等等。
示例需求
df_demand = pd.DataFrame(np.array([[300, 200, 200, 180], [300, 150, 200, 150]]), columns=['April', 'May', 'June', 'July'])
示例容量
df_cap = pd.DataFrame(np.array([[250, 220, 220, 250], [200, 200, 250, 200]]), columns=['April', 'May', 'June', 'July'])
你會如何處理這個問題?
沒有蟒蛇
def fun(d, c, r):
# Given current demand, capacity and residual
# find the currently meet demand and left over residual
d = d + r
if c >= d:
return d, 0
else:
return c, d-c
forecast = []
for index, cap in df_cap.iterrows():
if index not in df_demand.index:
continue
demand = df_demand.loc[index]
forecast.append([])
r = 0
for i, c in enumerate(cap):
d = demand[i]
f, r = fun(d,c,r)
forecast[-1].append(f)
print (pd.DataFrame(forecast, columns=df_cap.columns))
輸出
April May June July
0 250 220 220 190
1 200 200 250 150
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.