HOW TO

Extract and sum numbers from a text field using Python in ArcGIS Pro

First Published: June 9, 2026
Last Published: June 9, 2026

Summary

In ArcGIS Pro, Python can be used to extract and sum numeric values from a text field containing alphanumeric data. This is useful when numeric information embedded in text strings is extracted for calculations, such as summing quantities, unit numbers, or identification values.

This article provides the workflow to extract and sum numbers from a text field using Python in ArcGIS Pro.

Procedure

  1. In ArcGIS Pro, open the project.
  2. Open the attribute table containing the text field.
  3. Add a new integer field to the attribute table. Refer to ArcGIS Pro: Add Field (Data Management Tools) for instructions. In this example, the newly added field is Total Task Status.
  4. In the attribute table, right-click the newly added field and click Calculate Field.
    1. In the Calculate Field window, for Expression Type, ensure the default Python option is selected from the drop-down list.
    2. For Expression, in the first expression box, specify the code provided below. Replace <fieldName> by double-clicking the text field in the Fields list.
extract_sum(!<fieldName>!)
  1. In the Code Block box, specify the following expression:
import re

def extract_sum(value):
    if value:
        return sum([int(x) for x in re.findall(r'\d+', value)])
    return 0
The Calculate Field window
  1. Click Verify The Verify icon to validate the expression.
  2. Click Apply > OK.

The attribute table below shows the sum of numbers extracted from the text field for each record.

The values populated in the new field

Article ID: 000041850

Software:
  • ArcGIS Pro

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options