【问题标题】:How to find the indices of a certain value in pandas series [duplicate]如何在熊猫系列中找到某个值的索引[重复]
【发布时间】:2022-02-18 05:40:32
【问题描述】:

假设我有一个熊猫系列:

a = [1 ,2 ,4 ,2 ,7 , 2 ,8]

如何告诉 Python 返回值为 2 的索引?

谢谢。

【问题讨论】:

  • 那不是熊猫系列;但是对于熊猫系列,请尝试:a.index[a.eq(2)].tolist()

标签: python python-3.x pandas list dataframe


【解决方案1】:

我认为这应该可行。假设 a 是 pandas 系列。

f = a==2
indices = f[f].index

【讨论】:

    猜你喜欢
    • 2018-12-29
    • 2013-08-07
    • 1970-01-01
    • 2022-11-08
    • 2020-05-01
    • 2020-08-02
    • 2013-08-22
    相关资源
    最近更新 更多