Reputation: 844
From the following code:
aps1.Status.head(10)
Out[663]:
0 OK
1 OK
2 OK
3 OK
4 OK
5 OK
6 Fail
7 OK
8 Fail
9 OK
How to obtain the indexes for which Status is Fail? I tried:
print (index for index,value in enumerate(aps1.Status) if value == "Fail"])
But I'm getting syntax error. Thanks
Upvotes: 0
Views: 43
Reputation: 4233
use a list comprehension with a iterrows on the dataframe with an if condition for Status column
status=['OK'
,'OK'
,'OK'
,'OK'
,'OK'
,'OK'
,'Fail'
,'OK'
,'Fail'
,'OK']
df=pd.DataFrame({'Status':status})
df.reset_index(inplace=True)
print([index for index,item in df.iterrows() if item['Status']=='Fail'])
output [6, 8]
Upvotes: 0
Reputation: 175
You are getting that error because of the extra ] . Try deleting it
Upvotes: 1
Reputation: 731
remove the ']' at the end
print (index for index,value in enumerate(aps1.Status) if value == "Fail"**]**)
Upvotes: 2
Reputation: 862406
Use boolean indexing
with index
:
L = aps1.index[aps1.Status == 'Fail']
Upvotes: 2