0

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! )
4
  • 2
    The function is named reclass. Where is TextValue 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. – Vince Aug 11 '20 at 14:59
  • Was at the top of the script and i have placed it. That was an error on my part. I keep in mind using '>=' and < for the furture. – justin landolt Aug 11 '20 at 19:28
  • BENCH_1 = TextValue( !BENCH_1! ) doesn't make much sense in this context. If you want to calculate bench_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 early return directives, there is no difference between elif and if inside the function. – Vince Aug 11 '20 at 21:49
  • Have a look at gis.stackexchange.com/questions/177652/… it requires very little modification to achieve what you are after. – FelixIP Aug 13 '20 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.