Summary
In ArcGIS Pro, it is possible to remove the numerical values from a string field in an attribute table using a Python function. This is useful for data management, such as when only alphabetical values are required in a string field. This article provides the workflow to remove numbers from the values in a string field using the strip() Python function in the Calculate Field tool.
In this example, the numbers in the Street field are removed to display only non-numeric values.
Procedure
- Open the ArcGIS Pro project.
- In the Contents pane, right-click the feature layer and click Attribute Table.
- In the attribute table, right-click the field name, and select Calculate Field. In this example, the Street field is selected.
- In the Calculate Field window, specify the following parameters:
- For Input Table, ensure the layer selected in Step 2 is prefilled. In this example, the input table is Test.
- For Field Name, ensure the field selected in Step 3 is prefilled. In this example, the field name is Street.
- For Expression Type, select Python.
- For Expression, in the first expression box, specify the code provided below. Replace 'Field_Name' with the name of the field selected in Step 3.
strip_digits(!Field_Name!)
- In the Code Block box, specify the following expression.
import re
def strip_digits(s):
return re.sub("\d+", "", s)
- Click the Verify icon to validate the expression.
- Click OK to run the script.
The image below displays the Street field without numbers in the attribute table.