Notice the syntax in the following example
you have to have a function (ie def reclass) which you pass parameters to (ie a), but in the expression box, you will notice that you pass a field name enclosed in double quotes to the function (ie reclass(!Id!) in the example.
Now the function is specific about indentation. 4 spaces is standard, with the def line unindented. The if statement in my example does an equality check notice the colon at the end. If the equality is met, then the variable 'a' is assigned 1, it is indented 4 spaced. The 'else' section is where program focus moves it a doesn't equal 1, whereby a is assigned 0. Finally a value is returned. Now you can proceed to fix your code. In future, it would be better to copy and paste the snippet, so that people can edit your exact example without having to refer back to an image.
post your code since your indentation is not correct in the if block since 4 spaces per indentation level. If you have many to reclass, then an if else approach is not the one to take.
if a == 'Wicomico':
elif a == 'Cecil':
I need to classify 33 counties (for 287 camera records) into 7 districts. If I don't use if statement, what else can I use? Thanks
a nested if statement with 33 comparisons is not the route to go. producing a separate table for join/relates to do the conversion is what I was referring to.
Okay, Thanks again!
If your If statement do return you do not need to use elif
if a == 'Wicmico': return 1
if a == 'Cecil': return 2
Then it does not look so wrong.
When you say it isn't working, what do you mean, exactly? Is it generating an error? If so, post the error. Is it giving unexpected results? What are those results and how do they differ from what you expect?
Also, what you just posted here doesn't line up exactly with your screenshot. The screenshot appears to show an extra gap between the 2 equals signs for the second comparison. Also, your indentation above is all off, this is how it should look when/if using 4 spaces:
def reclass(a): if a == 'Wicomico': return 1 elif a == 'Cecil': return 2 else: return 0