Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use the Field Calculator with a python elif statement to reclassify values from a different field and populate a new field, and while I'm not getting an error message of any kind, I'm also not getting any sort of result. In other words, the tool runs and it says that it succeeded but nothing has changed in the column that is being calculated.

In codeblock example below the column that I want to use the elif statement on is "pa_gNyr_ha" and the new column that I want to populate is "N_load_bin".

def Reclass(Nload):
  if (Nload >= 0 and Nload <= 10000):   
    return 5000  
  elif (Nload > 10000 and Nload <= 24000):    
    return 17000  
  elif (Nload > 24000 and Nload <= 40000):    
    return 37000
  elif (Nload > 40000 and Nload <= 58000):
    return 50000
  elif (Nload > 58000 and Nload <= 74000):
    return 66000
  elif (Nload > 74000 and Nload <= 90000):
    return 82000
  elif (Nload > 90000 and Nload <= 104000):
    return 97000
  elif (Nload > 104000 and Nload <= 118000):
    return 111000
  elif (Nload > 118000 and Nload <= 130000):
    return 124000
  elif (Nload > 130000 and Nload <= 142000):
    return 136000
  elif (Nload > 142000 and Nload <= 157000):
    return 149500
  elif (Nload > 157000 and Nload <= 173000):
    return 165000
  elif (Nload > 173000 and Nload <= 189000):
    return 181000
  elif (Nload > 189000 and Nload <= 210000):
    return 194500
  elif (Nload > 210000 and Nload <= 233000):
    return 221500
  elif (Nload > 233000 and Nload <= 261000):
    return 242000
  elif (Nload > 261000 and Nload <= 299000):
    return 280000
  elif (Nload > 299000 and Nload <= 356000):
    return 327500
  elif (Nload > 356000 and Nload <= 456000):
    return 406000
  elif (Nload > 456000):
    return 501500

And then the expression is


Essentially what I'm trying to do is create a conditional statement that will look at a value in the "pa_gNyr_ha" field and return a value to the "N_load_bin" field based on the range it falls into.

Am I at least close?

share|improve this question
Don't see any mistakes. Maybe add at the end an else statement, just to see if it runs fine. Maybe else: return 9999. Let us know if that works. – ustroetz Nov 12 '13 at 23:00
Is it possible that the values in pa_gNy_ha are less than zero? Is the field definitely numeric? – Fezter Nov 12 '13 at 23:02
Is it possible that you have a selection on the feature class? If so, you may only be calculating on the selected features and not seeing the changes. – Fezter Nov 12 '13 at 23:04
Also what does the Results window say? (You find it under Geoprocessing>Results) – ustroetz Nov 12 '13 at 23:04
Your field delimiters should work for a file geodatabase - is that where you have a feature class stored or are you trying to use this on a shapefile? – PolyGeo Nov 12 '13 at 23:21

See PolyGeo's 1st comment to the original Question.

I was trying to use the Field Calculator and python codeblock on a shapefile and it worked as expected when the shapefile was exported to a geodatabase and the tool run on that file geodatabase feature class. PolyGeo rules.

share|improve this answer

The ArcMap calculator breaks Python rules and accepts only if, not the elif. Just replace all the elif code with if instead. It is correct that the file must be a geodatabase and not a shapefile.

share|improve this answer

If any of these conditional statements are true a value gets returned, but I don' t see any value assignment. So shouldn't your action after the if statement be something like:

if (Nload > 40000 and Nload <= 58000):
    N_load_bin= 5000

Have you run this script with the arcpy window open? Are these values being return to that window?

share|improve this answer
The syntax used by @SamP is correct in this regard - see the Calculate fields using logic with Python example on this help page to see that the return statement is needed. – PolyGeo Nov 13 '13 at 0:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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