Reputation: 2680
Short question:
I have the following (sample) dataframe:
df:
height weight hair
joe 5.6 123 brown
mary 5.2 110 blonde
pete 6.0 160 red
If I know the value in 'hair' is 'blonde', how do I get the index label (not integer location) corresponding to df.ix['mary','hair']? (In other words, I want to get 'mary' knowing that hair is 'blonde').
If I wanted the integer value of the index I'd use get_loc. But I want the label.
Thanks in advance.
Upvotes: 0
Views: 7207
Reputation: 720
If you want the first label:
df[df['hair'] == 'blonde'].index[0]
Or if you want all the values:
labels = df[df['hair'] == 'blonde'].index.values.tolist()
Upvotes: 2