HOW TO

Concatenate increment numbers and a text field using Python in ArcGIS Pro

Last Published: October 15, 2021

Summary

In ArcGIS Pro, the Calculate Field tool can be used to perform calculations on all or selected records using Python expressions. This article provides the workflow to concatenate increment numbers and an existing text field using Python.

Procedure

  1. In ArcGIS Pro, in the Contents pane, right-click the feature layer, and select Attribute Table.
  2. In the table view pane, right-click the existing text field header, and select Calculate Field. In this example, the text field is Text1.
Open the Calculate Field tool by right-clicking the text field header in the table view pane, and select Calculate Field on the menu.
  1. In the Calculate Field window, type a new name in Field Name to populate the calculation output to a new field. In this example, the name of the new field is Text_AutoIncrement.
Note:
This step can be skipped to populate the calculation output to the existing text field.
In the Calculate Field window, create a new field to update the calculation by typing a new name in the Field Name parameter text box, or click the drop-down menu to select an existing field.
  1. In the expression box, type the following code. Replace 'Field Name' with the name of the existing text field.
str(!Field Name!)+" "+str(autoIncrement())
Note:
Do not remove the exclamation marks surrounding the field name. Remove the double quotation marks (" ") to eliminate the space if required. 
  1. Copy and paste the following into the Code Block box.
rec=0
def autoIncrement():
    global rec
    pStart = 1  # adjust start value, if req'd 
    pInterval = 1  # adjust interval value, if req'd
    if (rec == 0): 
        rec = pStart 
    else: 
        rec = rec + pInterval 
    return rec
For the Python expression, type the expression in the Expression box for Step 4, and copy and paste the autoIncrement() code into the Code Block box for Step 5.
  1. Click Apply.
  2. Click OK to close the Calculate Field window. The new field, Text_AutoIncrement is populated with values from the existing text field and the increment numbers.
The output of the calculation is populated in the new field created. The output results follow the expression of: the existing text field, space, and the increment number.

Article ID: 000026359

Software:
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options