Reputation: 7
This is the dataframe I have I need to get the following:
empid role
123 lead
124 lead
125 manager
156 lead
129 manager
while iterating over each value of a column role I need to get the value of empid if role == lead and store it in another variable
Upvotes: 0
Views: 592
Reputation: 120409
Use .loc
:
>>> df.loc[df['role'] == 'lead', 'empid']
0 123
1 124
3 156
Name: empid, dtype: int64
If you want a list:
empid = df.loc[df['role'] == 'lead', 'empid'].tolist()
>>> empid
[123, 124, 156]
Read the documentation Indexing and selecting data
Upvotes: 1