我有一个由item_id(数字)索引的pandas DataFrame,我尝试使用DataFrame.loc[str(item_id),word]
访问某个位置的项目,其中word是我要访问的列的标签。 Word是一个字符串:
print(output.loc[str(df.loc[i,'item_id']),word])
我得到的输出如下:
hu 0.0
hu 0.0
Name: 17349826, dtype: float64
此处单词的值为hu
,item_id
的值为17349826
。
我希望输出只是:
0.0
答案 0 :(得分:0)
我认为你需要为iat
选择Series
的拳头值作为标量输出:
print(output.loc[str(df.loc[i,'item_id']),word]).iat[0]
重复输出的原因与index
值重复。