Using Calculate Field Tool to calculate a value in a table based on another field using Python

In some cases, you may want to calculate a field based on the value of another field. A good example of this would be when you may want to create or calculate domain code values from a description field.

In the following example we are using some Tree data to calculate the Risk_Code associated with the Risk description which can then later be used as a Domain.

  • To begin, open the Attribute Table for the data in ArcGIS Pro
  • Select applicable field to calculate (i.e. RISK_CODE)
  • Right click field (RISK_CODE) > Field Calculator
  • Select Python 3 as the Expression Type

Code Block

def calcRiskCode(riskDesc):
     if riskDesc == "High":
         return 1
     elif riskDesc == "Medium":
         return 2
     elif riskDesc == "Low":
         return 3
         return 0



  • Click OK.

For example:


Further Calculate Field Examples:

Sam Pienaar.

Got something to say?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s