JavaScript
x
12
12
1
sex age pets
2
0 M 21 [cat, dog]
3
1 M 45 [hamster]
4
2 F 23 [cat, gerbil]
5
3 M 56 [fish, hamster, gerbil]
6
4 F 47 [cat]
7
5 F 70 [dog]
8
6 F 34 [dog]
9
7 M 30 [cat]
10
8 F 19 [rabbit, cat]
11
9 M 62 [dog]
12
I’m trying to use .loc
to find out sex of the youngest person here in the chart.
The following did not work:
JavaScript
1
2
1
pd.DataFrame.loc['age', 'sex']
2
Advertisement
Answer
You can achieve it like this:
JavaScript
1
3
1
>>> print(df.loc[df.age == df.age.min(), 'sex'].values[0])
2
'F'
3