gpt4 book ai didi

python - Pandas :获取系列对象中的值(value)标签

转载 作者:太空狗 更新时间:2023-10-29 16:56:38 24 4
gpt4 key购买 nike

如何检索 pandas 系列对象中特定值的标签:

例如:

labels = ['a', 'b', 'c', 'd', 'e']
s = Series (arange(5) * 4 , labels)

产生系列:

a     0
b 4
c 8
d 12
e 16
dtype: int64

如何获得值为“12”的标签?谢谢

最佳答案

您可以通过以下方式获取子系列:

In [90]: s[s==12]
Out[90]:
d 12
dtype: int64

此外,您可以通过以下方式获取这些标签

In [91]: s[s==12].index
Out[91]: Index([d], dtype=object)

关于python - Pandas :获取系列对象中的值(value)标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16435697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com