其中的值是0,我正在对其进行除法,这似乎抛出了一个错误。如何避免这种错误
wt pred wt remarks
0 14 Anomaly
0 20 Anomaly
25 30 Anomaly
22 21 Anomaly
21 102 Anomaly
def valuation_formula(x,y):
if float(abs(x-y)/y*100) > 25.0:
return "Anomaly"
else :
return "Pass"
try:
df_Wt['Weight_Remarks'] = df_Wt.apply(lambda row:
valuation_formula(row['Predicted Weight'], row['Weight']), axis=1)
except ZeroDivisionError:
df_Wt['Weight_Remarks'] = "Anomaly"
新列只填充了“异常”如何更正上面的代码
预期产量
^{pr2}$
使用
numpy.where
:输出:
^{pr2}$试试这个代码
我认为您输入的输出与函数不匹配。至少有一个值应为“Weight Anamoly”。调整
lt(0.25)
以获得所需的结果。它代表“小于”,您可以将其更改为“gt”(大于),以满足您的需要相关问题 更多 >
编程相关推荐