Hello,
I have two attributes for counties and districts. I need to write a script in Python to get the District IDs based on the counties. I am not a developer so I may have mistakes in my script attached. I appreciate your help.
Thanks.
def reclass(a): if a == 'Wicomico': return 1 elif a == 'Cecil': return 2 else: return 0
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.
Thanks or your response. I followed all your instructions (please see the image attached). But it does not work. By the way, there are 33 counties, but I am just trying the code for two counties for now. Also, the County field is a string attribute and District is short integer.
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.
Good luck
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.