我已经把一个数据帧转换成了一个字典,并且在一个for函数中使用了一个字典值,但是它给了我以下的错误
df =
Metal Medium Carbon Steel
Max Compressive Stress/MPa 305
Cost per m^3/$ 4301
I/mm^4 3.27869e+07
inner_radius_quarted 5.82544e+07
inner_radius/mm 87.3639
thickness/mm 12.6361
volume/mm^3 12636.1
cost/$ 0.0543477
a1 = df.to_dict()
P = [P -1,P +1]
for i in P:
x = (i * L * y) / (a1[1][u'I/mm^4'] * 4)
if x > a1[1][u'Max Compressive Stress/MPa']:
print "A point load of", i, ", will break the beam"
else:
print "A point load of", i, ", will not break the beam"
KeyError Traceback (most recent call last)
<ipython-input-255-8d9325dc6d75> in <module>()
2
3 for i in P:
----> 4 x = (i * L * y) / (a1[1][u'I/mm^4'] * 4)
5 if x > a1[1][u'Max Compressive Stress/MPa']:
6 print "A point load of", i, ", will break the beam"
KeyError: 1
你看过
a1
吗。它并不是你想要的那样试试看
相关问题 更多 >
编程相关推荐