Summary
In ArcGIS Pro, Python or Arcade expressions can be used to create a new field without the unnecessary text strings of a field. This is common in address records whereby the street number is not required for analysis. Removing the leading text from a string can be used for data management or search results optimization.
This article provides an example and instructions using Python and Arcade expressions to remove leading text from a string in ArcGIS Pro.
The image below shows the ADRESS field with text string records.
Procedure
- In the Contents pane, right-click the feature class and click Attribute Table to open the attribute table of the feature class.
- Click Calculate to open the Calculate Field tool.
Note:
Refer to ArcGIS Pro: Calculate Field (Data Management) for more information on the parameters in the Calculate Field tool.
- In the Calculate Field dialog box, configure the following parameters:
- For Python 3:
- For Input Table, select the feature class.
- For Field Name (Existing or New), select the field to be edited or create a new field. In this example, 'PYTHONSPLITADDRESS' is created.
- For Expression Type, select Python 3.
- Specify the following script in the first text block. The 'maxSplitParameter' is the number of split elements. As an example, setting the 'maxSplitParameter' to 1, returns a list with two elements. The 'indexNumber' refers to an element of an iterable object by its position within the iterable object. As an example, setting the 'indexNumber' to 1, returns the second element.
!<fieldName>!.strip().split(" ",<maxSplitParameter>)[<indexNumber>]
The code block below is an example of the expression.
!ADDRESS!.strip().split(" ",1)[1]
- Click Verify to run a test of the expression. If the expression is valid, click OK.
- For Arcade expressions:
- For Input Table, select the feature class.
- For Field Name (Existing or New), select the field to be edited or create a new field. In this example, 'ARCADESPLITADDRESS' is created.
- For Expression Type, select Arcade.
- Specify the following Arcade expression in the Expression section:
- Define the variable to find a sequence of characters within a text value. In this example, 'varName1' is named as fstSpace.
var <varName1> = find(' ',$feature.<fieldName>,<startPosition>)
- Define the variable to count the number of characters in a text value. In this example, 'varName2' is named as strCount.
var <varName2> = Count($feature.<fieldName>)
- Define the variable to calculate the difference between 'varName1' and 'varName2'. In this example, 'varName3' is named as strDiff.
var <varName3> = <varName2> - <varName1>
- Specify the following statement to return the specified number of characters from the end of a text value.
return right($feature.<fieldName, <varName3>)
The code block below is an example of the full expression.
var fstSpace = Find(' ', $feature.ADDRESS, 0)
var strCount = Count($feature.ADDRESS)
var strDiff = strCount - fstSpace
return Right($feature.ADDRESS, strDiff)
- Click Verify to run a test of the expression. If the expression is valid, click OK.
The image below shows the 'PYTHONSPLITADDRESS' and 'ARCADESPLITADDRESS' fields added to the 'Schools_all' attribute table with the leading text removed from the 'ADDRESS' field using Python and Arcade expressions.