在熊猫系列中按值搜索

时间:2015-05-20 03:47:17

标签: python 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

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

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:0)

这是一种方法。

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

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

df.ix['some name'][df.ix['some name']==31].index.tolist()
相关问题