Reputation:
Give a pandas series
(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
.
Upvotes: 4
Views: 11626
Reputation: 76927
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()
Upvotes: 1