samedi 19 septembre 2015

Python IF statement always return True

This is a very small version of my script. I changed it to test the if statement. The value of the Boolean is False and that's right! When I change the value of row, highRisk always receive the correct value (True/False). But even with the correct value of highRisk the result is always "ok". Does anyone can explain me why?

row = 5

riskHigh = (reasons.iloc[row,1:2] == "high").bool

if riskHigh:
    print "ok"
else:
    print "oops"

Results:

In [60]: row = 5
    ...: riskHigh = (reasons.iloc[row,1:2] == "high").bool
    ...: 
    ...: if riskHigh:
    ...:     print "ok"
    ...: else:
    ...:     print "oops"
    ...: 
    ...: 
ok

In [61]: print riskHigh
<bound method Series.bool of Risk_Rating    False
Name: 5, dtype: bool

Aucun commentaire:

Enregistrer un commentaire