【问题标题】:Pandas: Get label for value in Series Object熊猫:获取系列对象中的值标签
【发布时间】:2013-05-02 09:21:03
【问题描述】:

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

例如:

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'的标签?谢谢

【问题讨论】:

    标签: python pandas series


    【解决方案1】:

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

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

    此外,您可以通过

    获得这些标签
    In [91]: s[s==12].index
    Out[91]: Index([d], dtype=object)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 2017-11-03
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多