在 pandas 系列中按值搜索

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30339923/
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 23:22:32  来源:igfitidea点击:

Search by value in pandas series

pythonpandas

提问by farhawa

Give a pandas series

给Pandas系列

(Pdb) type(dt.ix['some name'])
<class 'pandas.core.series.Series'>

(Pdb) df.ix['some name']
col1  5
col2  31
col3  3
col4  12

Name: some name, dtype: int64

How can I find the name of the column which has a value, say, 31? In this case it's col2.

如何找到具有值(例如 31)的列的名称?在这种情况下,它是col2.

回答by farhawa

myseries[myseries  == 'VALUE'].index.tolist() 

回答by Zero

Here's one way to do it.

这是一种方法。

In [13]: df.ix['some name'][df.ix['some name']==31].index[0]
Out[13]: 'col2'

THe above picks first value, however if you want all possible values, then do

上面选择第一个值,但是如果你想要所有可能的值,那么做

df.ix['some name'][df.ix['some name']==31].index.tolist()