简体   繁体   English

pandas.DataFrame.loc两次给出标签的输出,并提及Name和dtype

[英]pandas.DataFrame.loc gives output for a label twice and mentions Name and dtype

I have a pandas DataFrame indexed by item_id (numbers), I tried to access an item at a location by using DataFrame.loc[str(item_id),word] where word is the label of the column I want to access. 我有一个由item_id(数字)索引的熊猫DataFrame,我尝试通过使用DataFrame.loc[str(item_id),word]访问某个位置的项目,其中word是我要访问的列的标签。 Word is a string: Word是一个字符串:

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

The output I get is the following: 我得到的输出如下:

hu    0.0
hu    0.0
Name: 17349826, dtype: float64

here word has value hu and item_id had 17349826 . 这里的单词具有hu值, item_id具有17349826

I want the output as just: 我希望输出为:

0.0

I think you need select fist value of Series by iat for scalar output: 我认为您需要通过iat选择Series的拳头值作为标量输出:

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

And reason for duplicated output is duplicates in index values. 输出重复的原因是index值重复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM