English
Continue in the app
Be The First To Get Support Updates
Want to know about the latest technical content and software updates?

How To: Create sequential numbers in a field in ArcMap using Python in the Field Calculator

Summary

Instructions provided describe how to create sequential numbers in a field in ArcMap using Python in the Field Calculator.

Procedure

Note:
The code in this article generates sequential numbers for unsorted data based on the OID or FID order. If the data is sorted on a field, the generated numbers are not sequential.
  1. Create a new short integer field.
  2. Right-click the new field and select Field Calculator.
  3. Set the Parser to Python.
  4. Check the check box for Show Codeblock.
  5. Paste the following into the Pre-Logic Script Code:
rec=0 
def autoIncrement(): 
 global rec 
 pStart = 1  
 pInterval = 1 
 if (rec == 0):  
  rec = pStart  
 else:  
  rec += pInterval  
 return rec
  1. Paste the following code in the smaller box below the Pre-Logic Script Code:
autoIncrement()
  1. Click OK. The following image is an example of a field with sequential numbers populated using the Python code:
An attribute table with a field with sequential numbers.

Related Information

Last Published: 1/6/2022

Article ID: 000011137

Software: ArcGIS for Desktop Advanced 10.3.1, 10.3, 10.2.2, 10.2.1, 10.2, 10.1 ArcGIS for Desktop Basic 10.3.1, 10.3, 10.2.2, 10.2.1, 10.2, 10.1 ArcGIS for Desktop Standard 10.3.1, 10.3, 10.2.2, 10.2.1, 10.2, 10.1 ArcGIS-ArcEditor 10 ArcGIS-ArcInfo 10 ArcGIS-ArcView 10