import pandas as pd
data = {
'Date': ['2020-01-01', '2020-01-02', '2020-01-03', '2020-01-04',
'2020-02-01', '2020-02-08', '2020-02-15', '2020-02-22',
'2020-02-29','2020-03-07','2020-03-15','2020-03-22'],
'stock': [5, 0, 0, 0
, 0, 0, 0, 0
, 0, 0, 0, 0],
'in': [14, 4, 29, 2
, 0, 0, 0, 0
, 0, 0, 0, 0],
'out': [-10, -25, -8,-8
, -8, -8, -8, -8
, -8, -8, -8, -8],
'supplier': [0, 0, 0,0
, 0, 0, 0, 0
, 0, 0, 0, 0]
}
df1 = pd.DataFrame ( data, columns=['Date', 'stock', 'in', 'out','supplier'] )
df1['Sum_Stock'] = df1['stock'] + df1['in'] + df1['out']+df1['supplier']
df1['cum_Stock'] = df1['Sum_Stock'].cumsum ( axis=0 )
print ( df1 )
如何更新“供应商”列并使每行的['cum_Stock']大于0。
如果['cum_Stock']大于0,则“供应商”为0。
“供应商”不能为负,但应最小化。
谢谢!