Quickly Transform Text Values to Numbers in ArcGIS Pro with Python If statement

If you have a table with values of text that you want to change into numeric values to manipulate symbology, you can use the Python Code Block in the Calculate Field tool.

I want to add a column of numbers to correspond to these text descriptions

Non-detect -> 1
Low -> 1
Moderate -> 2
High -> 3
Very High -> 4

To do this, I’ll open the table in ArcGIS Pro, then click the Calculate button to open the Calculate Field Panel

In Calculate Field, chose the the table you want to edit, add a new field for your numbers “riskNumbers,” then make that a Long Integer field.

After the “=” add the code:

makeNumbers(!riskName!)

Then in the Code Block Section we’ll define our makeNumbers function:

def makeNumbers(risk):
    if risk == 'Non-detectable':
        return 0
    elif risk == 'Low':
        return 1
    elif risk == 'Moderate':
        return 2
    elif risk == 'High':
        return 3
    elif risk == 'Very High':
        return 4

Check your new RiskNumber column and spot check to make sure it worked.

Now you can go on to add gradient symbology to your data.