我正在尝试导入我的计算器,使用spyder在熊猫木星上创建,但收到了上述错误。尝试使用其他:但仍然得到错误。
这是我的间谍密码。
import pandas as pd
def calc_convert(Unit,result):
if Unit == 'mg/g':
testr = result*0.100
elif Unit == 'g/day':
testr = result*100
elif Unit == 'g/g':
testr = result*0.100*1000
else:
testr = result*1
return testr这是我的熊猫密码
lst_test = []
for index, row in test.iterrows():
lst_test.append(calc_convert(row['Unit'],row['result']))
test['converted'] = pd.Series(lst_test,index=test.index)
display(test)这是朱庇特熊猫的追踪错误
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-170-5dfe9296da1e> in <module>
1 lst_test = []
2 for index, row in test.iterrows():
----> 3 lst_test.append(calc_convert(row['Unit'], row['result']))
4
5 test['converted'] = pd.Series(lst_test, index=test.index)
17 elif Unit == 'g/g':
18 testr = result*0.100*1000
---> 19 else:
20 testr = result*1
21
UnboundLocalError: local variable 'testr' referenced before assignment发布于 2022-04-11 02:55:54
重新启动内核起作用了。感谢大家的投入。
https://stackoverflow.com/questions/71822031
复制相似问题