我的任务如下:
如你所见,我有10列
我需要创建一个新的列“WhseFrom”,它将返回7个(AH、AYC、MAEG、MAR、ROT、WITZ、BUD)列中的一个列的值名,这些列基于此表背后的思想产生的优先级条件:
然后,这个新列“Pull2”上应该包含的值应该基于条件
例如,当store==BUD时,跟踪器数据应检查while Pull列是否大于0,如果WHSE==WITZ中的数量足够(等于或高于)Pull列中的数量,如果是,则应中断搜索并返回Pull值,但如果不是,跟踪器功能将继续,因此检查WHSE==ROT中的数量,如果仍然不够,则继续并检查优先级列列表中的后续WHSE
对于所有其他商店=='WHSE',也必须执行此场景
如有任何想法或建议,将不胜感激
我试图创建以下代码:
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
但正如您所看到的,在跟踪所涉及商店的第一个条件后,仍然缺少可能性
请,我需要关于如何在Python上开发它的建议
对于数据操作,请按照以下示例创建“表a”:
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
因此,预期返回的列是WHSEFrom,它将在每一行检查store==BUD的Pull列中是否有足够的数量,数量first all在WITZ列中,如果是,它将在WHSEFrom列中中断并返回该WHSE WITZ的名称。如果没有,它将检查其他6个仓库是否有符合PULLWH数据透视表(p1>;p2>;p3>;p4>;p5)中优先级规则的最小数量
任何帮助都将不胜感激
输出应类似于以下示例中共享的“预期输出表”:
试试这个:
相关问题 更多 >
编程相关推荐