How To: Create sequential numbers in a field using Python in the Field Calculator
Instructions provided describe how to create sequential numbers in a field using Python in the Field Calculator.
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 will not be sequential.
- Create a new short integer field.
- Right-click the new field and select Field Calculator.
- Set the Parser to Python.
- Check the check box for Show Codeblock.
- Paste the following into the Pre-Logic Script Code:
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
rec += pInterval
- Paste the following code in the smaller box below the Pre-Logic Script Code:
- Click OK. The following image is an example of a field with sequential numbers populated using the Python code:
Last Published: 7/26/2018
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 ArcMap 10.6.1, 10.6