I am trying to populate a field with a text string based on a combination of two other fields. The field !yearsSinceAct! is a decimal (float) of years. !OperationalStatus! is a text field describing whether or not a particular feature is operable or not. The three options for !OperationalStatus! are "OK", "Inoperable", and null
actionRating =
Reclass(!yearsSinceAct!,!OperationalStatus!)
def Reclass(Rating,Operation):
if (Rating <= 1) and (Operation = "OK"):
return "Recently operated or serviced"
elif (1 < Rating <= 5) and (Operation = "OK"):
return "Operated or serviced between 1 and 5 years ago"
elif (Rating > 5) and (Operation = "OK"):
return "Last known to be OK but no promises; it's been a minute"
elif (Rating <= 1) and (Operation = "Inoperable"):
return "Recently found to be non-functioning"
elif (1 < Rating <= 5) and (Operation = "Inoperable"):
return "Found to be dysfunctional and has not been repaired in 1-5 years"
elif (Rating > 5) and (Operation = "Inoperable"):
return "This valve has been left in the dust"
else:
return "Unknown"
I can't get this code block to work. I tried assigning the outputs to a variable and then returning that variable at the end too with no success. Any ideas?
1 Answer 1
According to Comparisons - Built-in Types - Python 3.x documentation:
This table summarizes the comparison operations:
Operation Meaning < strictly less than <= less than or equal > strictly greater than >= greater than or equal == equal != not equal is object identity is not negated object identity
The existing code is using a single equals sign, which is an assignment statement. What is needed is two equal signs, which is an equality comparison.
Explore related questions
See similar questions with these tags.