pandas.DataFrame.loc为标签提供两次输出,并提到Name和dtype

时间:2017-12-06 08:36:13

标签: python pandas

我有一个由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

此处单词的值为huitem_id的值为17349826

我希望输出只是:

0.0

1 个答案:

答案 0 :(得分:0)

我认为你需要为iat选择Series的拳头值作为标量输出:

print(output.loc[str(df.loc[i,'item_id']),word]).iat[0]

重复输出的原因与index值重复。