我有一个字典
d = {1:a,2:a}
我还有一个名为“df”的pandas数据框。
0 x y
1 1 10
2 2 56
由于某种原因,我无法将x值与字典键匹配起来。
for index, row in df.iterrows():
for x,y in d.items():
if row['x'] == x:
print "Got a Match"
else:
print "No Match Found"
我只得到了“未找到匹配项”的结果。 我做错了什么吗? 在pandas系列中的数据是“float64”,而字典中的键是“int”,但我将pandas系列转换为int后,仍然无法匹配这些项。 如有帮助,请指教。
谢谢!
print(row['x'], x)
- Ted Petrou