I have a String field ('Prefix') and a Double field ('Result'). I am trying to group data by a specific range, <0.002, 0.002 to 0.07, >0.07, however some values have a '<' or '>' prefix contained in the String field. This causes me issues where i have the value 0.07 in one cell and the value 0.07 in another cell with the prefix '<', which represent 0.07 and <0.07 respectively.

What I would like to do is create a new Double attribute called 'Result_Edit'(easy enough) and use Field Calculator to look for all cases where the 'Prefix' field (String) has a '<' or '>' and the 'Result' is 0.002 or 0.07, and either return 0.0019 or 0.071 to the corresponding 'Result' field (Double). The values that have no prefix will remain as they are.

Prefix | Result | Result_Edit







I only care about <0.002 and >0.07.

This is what I have, but it doesn't work.....

def EDIT ( Prefix , Result , Result_Edit ):
  if (Prefix = '<' & Result = 0.002):
    return 0.0019
  elif (Prefix = '>' & Result =0.07):
    return  0.071
    return Result

EDIT ( !Prefix! , !Result! , !Result_Edit! )

Using ArcGIS Desktop v 10.5 with Python checked.

1 Answer 1


The logic of the code it's Ok, but you have some sintax errors. First of all, when executing this code it should give you a message telling that there was a failure and check the Results window, and there you can see that you have (at least) a sintax error in line 2.

Now, you have two sintax mistakes. First, you are using '=' to compare, but it is the assign operator. The compare operator is '==', at first is a bit confusing but you get used to it. The second mistake, is the '&' operator, this is used in other languages, but in python you should use 'and'. The final code will be this, and now it should run fine:

def EDIT ( Prefix , Result , Result_Edit ):
  if (Prefix == '<' and Result == 0.002):
    return 0.0019
  elif (Prefix == '>' and Result == 0.07):
    return  0.071
    return Result
  • That did the trick, thanks! Classic rookie mistake! Appreciate the help.
    – Jamie
    Dec 20, 2017 at 6:43
  • & is a binary AND; just like with the equals sign, you'd have to use && for it to work as expected, as in other languages. However python doesn't support that syntax at all. Dec 20, 2017 at 9:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.