After some initial research, I was unable to find a solution for the following issue. I'm sure there's an answer to this question already floating around here somewhere, but hopefully someone can give me a more personalized answer for my particular situation.

I am using ArcMap 10.3

I would like to have a String field that automatically generates a category name based off of an Integer field range.
Basically: If the Integer is between 0-500, the String would generate "Red" for the category field.
There are 5 different Categories to choose from within my Integer data.

To my understanding, this would need to happen via the Field Calculator, using a code block and Python.

Can I generate a String result in Field1 based on a designated Integer range in Field2?
If so, How?

  • Out of curiosity, are you trying to use these categories to define symbology/colors for these features for display? If so, maybe using graduated colors symbology may be a better way to go - resources.arcgis.com/en/help/main/10.1/index.html#//… Not sure of your familiarity with ArcGIS, so just checking to make sure you're not trying to reinvent an existing feature.
    – MWrenn
    May 6, 2015 at 21:00
  • I was going to convert my Symbology to use graduated symbols instead of the color categories, but, the color categories needs to be part of my data anyway. So, the numbers dictate the color category, and the color category dictates my symbology.
    – Nomkins
    May 6, 2015 at 21:45

3 Answers 3


In the pre-logic script code block (after having chosen python as the parser), you'll want something similar to this -

def categorize(value):
    if 0 <= value <= 500:
        return 'red'
    elif 501 <= value <= 1000:
        return 'green'
        return 'light purple'

and in the text box below it, you'll want to call the functio nyou just defined, passing in field names as paramaters using !fieldname! notation like so -

  • Am I correct in assuming this operation is done while I have the Color Category field highlighted, not the Integer field?
    – Nomkins
    May 7, 2015 at 13:43
  • @Nomkins correct
    – nmpeterson
    May 7, 2015 at 14:00
  • Any time I try to run this using the field calculator, ArcMap crashes. Even when I narrow down my selected items to 10 or so. Any thoughts on why that might be?
    – Nomkins
    May 7, 2015 at 14:38
  • Do you get any error messages? The only thing I can think of off the top of my head is that either you've somehow corrupted your python installation, or maybe you're just not selecting the Python parser option at the top of the field calculator where it has radio button for Pythong & VB
    – MWrenn
    May 8, 2015 at 14:21

You can use an Update Cursor to do this type of classification:

import arcpy

fc = r'C:\temp\yourFC.shp'

with arcpy.da.UpdateCursor(fc, ["Field1", "Field2"]) as cursor:
    for row in cursor:
        # row[0] = "Field1"
        # row[1] = "Field2"
        if  500 >= row[1] >= 0:
            row[0] = "red"
        elif  1000 >= row[1] > 500:
            row[0] = "green"
        elif  1500 >= row[1] > 1000:
            row[0] = "blue"
            row[0] = "unassigned"

enter image description here


Yeah, you have a basic if/else logic, check out this: Basic If/Then in Python Parser of ArcGIS Field Calculator?

dim n if[integerfield] > 500 then n = 'Red' elseif[integerfield].....

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.