I have the follow task:
I do have a table as we can see bellow: 
As you can see, I have 10 columns.
I need to create a new column "WhseFrom" which will return the value name of one of the 7 (AH,AYC,MAEG,MAR,ROT,WITZ,BUD) columnS based on the such prioritization conditions that comes from the idea behind this table:
Then, the values that shouold contain on this new column "Pull2" should be based on the conditions.
As example, while the store == BUD, the tracker data should check while Pull column is higher than 0, if the quantity in the WHSE== WITZ is enough(equal or higher) than in the Pull column, if yes, it should break the search and return the Pull value, but if not, the tracker function sholuld continue and so check the quantities in the WHSE== ROT, and if still not enough, continue and check on the follow WHSE which follow from the column list of priorization.
This scenario must be done also for all the other store=='WHSE'.
Any idea or suggestions would be very appreciate.
I was trying to create the follow code:
def findQty(row):
while row['store']== 'BUD' and row['Pull'] > 0:
if row['Pull'] >= row['ROT']:
return row['Pull']
continue
else:
if row['Pull'] < row['ROT']:
return (row['WITZ'] - row['Pull'])
break #maybe here include other columns
else:
pass
else:
pass
while row['store']== 'WITZ' and row['Pull'] > 0:
if row['Pull'] >= row['WITZ']:
return row['Pull']
continue
else:
if row['Pull'] < row['WITZ']:
return (row['WITZ'] - row['Pull'])
break
else:
pass
else:
pass
while row['store']== 'MAR' and row['Pull'] > 0:
if row['Pull'] >= row['WITZ']:
return row['Pull']
continue
else:
if row['Pull'] < row['WITZ']:
return (row['WITZ'] - row['Pull'])
break
else:
pass
else:
pass
while row['store']== 'ROT' and row['Pull'] > 0:
if row['Pull'] >= row['WITZ']:
return row['Pull']
continue
else:
if row['Pull'] < row['WITZ']:
return (row['WITZ'] - row['Pull'])
break
else:
pass
else:
pass
while row['store']== 'MAEG' and row['Pull'] > 0:
if row['Pull'] >= row['ROT']:
return row['Pull']
continue
else:
if row['Pull'] < row['ROT']:
return (row['WITZ'] - row['Pull'])
break
else:
pass
else:
pass
while row['store']== 'AYC' and row['Pull'] > 0:
if row['Pull'] >= row['WITZ']:
return row['Pull']
continue
elif row['Pull'] < row['WITZ']:
return (row['WITZ'] - row['Pull'])
break
But as you can see, still missing the possibilites once the first condition for the store in question is being tracked.
Please, I need suggestion in how it would be developed it on Python.
For the data manipulation, follow a sample to create the "table A" bellow:
import pandas as pd
tabela = [ (8489,'BUD', 175,0,0,0,0,0,1522,0 )]
tabeladf = pd.DataFrame(tabela)
tabeladf
tabeladf.columns = ['PNO','store', 'Pull', 'ADH','AYC',
'MAEG','MAR','ROT', 'WITZ','BUD' ]
tabeladf
def findQty(row):
while row['store']== 'BUD' and row['Pull'] > 0:
if row['Pull'] >= row['ROT']:
return row['Pull']
continue
else:
if row['Pull'] < row['ROT']:
return (row['WITZ'] - row['Pull'])
break #maybe here include other columns
else:
pass
tabeladf['WhseFrom'] = tabeladf.apply(findQty, axis=1)
tabeladf
So the expected column to be returned is this WHSEFrom, which will check in each row if for the store==BUD we do have enough quantity in the Pull column with the quantity fisrt all in the WITZ column, if yes, it will break and return the name of this WHSE WITZ on this column WhseFrom. If no, it willcheck in the other 6 warehouses if we have the minimum quantity following the rules of prioritization in the PULLWH pivot table(p1>p2>p3>p4>p5).

Aucun commentaire:
Enregistrer un commentaire