gpt4 book ai didi

python Pandas : Getting the locations of a value in dataframe

转载 作者:太空狗 更新时间:2023-10-29 21:22:08 25 4
gpt4 key购买 nike

假设我有以下数据框:

   'a' 'b'
0 0 0
1 1 0
2 0 1
3 0 1

有没有办法获取存在特定值的索引/列值?例如,类似于以下内容:

values = df.search(1)

将有 values = [(1, 'a'), (2, 'b'), (3, 'b')]

最佳答案

df[df == 1].stack().index.tolist()

产量

[(1, 'a'), (2, 'b'), (3, 'b')]

关于 python Pandas : Getting the locations of a value in dataframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28979794/

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