I am new to Python and I'm trying to write a simple if then statement in Field Calculator in ArcGIS 10.2.2 that will take the values from a numeric field and add them to a string field. I can't figure out which python function to use. When i try this code, it works but all values in my text field become "N/A."
This is what I put in the Pre-logic Script Code:
def change(Value):
if Value == 1:
return "Developed"
elif Value == 2:
return "Agriculture"
elif Value == 3:
return "Forested"
elif Value == 4:
return "Water"
elif Value == 5:
return "Wetlands"
else:
return "N/A"
if Value == "1"
etc. and changing the expression tochange(str(!Type!))
. BTW, in your question you can add 4 spaces in front of your code in to get the nice formatting.!Value!
because the Value field values are the ones you want to have passed through your code-block. You can probably remove the string casting idea that I had. So go back tochange(!Value!)
andValue == 1
. Understand that in the code block, you are not actually referencing any fields or the values in them, you are just defining how the values that expression are handled.