Pandas:获取系列对象中的值标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16435697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:48:37  来源:igfitidea点击:

Pandas: Get label for value in Series Object

pythonpandasseries

提问by Andy

How is it possible to retrieve the labe of a particular value in a pandas Series object:

如何在 Pandas Series 对象中检索特定值的标签:

For example:

例如:

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

Which produces the Series:

产生系列:

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

How is it possible to get the label of value '12'? Thanks

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

采纳答案by waitingkuo

You can get the subseries by:

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

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

Moreover, you can get those labels by

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

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