I am an experienced ArcMap user who is fairly new to Python. I am having trouble getting the script to look for a list of values and assign a new label in a new column. The script runs without errors but it does not fill in the new column.
Do the two columns need to be the same type?
I have provided the code that I use in the code block of the field calculator. In the other half of the field calculator I have
def reclass(Landing_Factor):
if Landing_Factor >=1.0 and Landing_Factor <=1.99:
return "A"
elif Landing_Factor >= 2 and Landing_Factor <=2.99:
return "B"
elif Landing_Factor >= 3 and Landing_Factor <=3.99:
return "C"
elif Landing_Factor >= 4 and Landing_Factor <=4.99:
return "D"
elif Landing_Factor >= 5 and Landing_Factor <=5.99:
return "E"
elif Landing_Factor >= 6 and Landing_Factor <=6.99:
return "F"
elif Landing_Factor >= 7 and Landing_Factor <=7.99:
return "G"
elif Landing_Factor >= 8 and Landing_Factor <=8.99:
return "H"
elif Landing_Factor >= 9 and Landing_Factor <=9.99:
return "I"
else:
return "N/A"
BENCH_1 = TextValue( !BENCH_1! )
justin landoltjustin landolt
asked Aug 11, 2020 at 14:31
lang-py
reclass
. Where isTextValue
defined? Note that your comparison operators leave room for 7.99000000001 to be encoded 'N/A' -- it is much safer to use '>=' and<
together to prevent floating-point representation artifacts.BENCH_1 = TextValue( !BENCH_1! )
doesn't make much sense in this context. If you want to calculatebench_2 = reclass( !BENCH_1!)
, that would make sense (where Bench_2 is a Text field of at least width 3). Note that, since you use earlyreturn
directives, there is no difference betweenelif
andif
inside the function.