Summary
In ArcGIS Pro, a text field may contain values separated by delimiters, and it is sometimes necessary to separate the last values into a new field for data analysis. This can be achieved in ArcGIS Pro using the split() method in the Calculate Field function.
The workflow provided in this article involves splitting the last values based on either a delimiter or multiple delimiters, and populating them into a new field using the Calculate Field function. In this example, the Address text field contains values separated by three different delimiters.
Procedure
- In ArcGIS Pro, create a new field to populate the last values.
- In the Contents pane, right-click the feature layer or the stand-alone table containing the text values, navigate to Data Design and click Fields.
- Follow the workflow described in ArcGIS Pro: Create a field and apply a domain and default value to add a new field to the attribute table. In this example, a new text field named Suffix is created.
- On the Fields tab, click Save.
- In the Contents pane, right-click the feature layer or the stand-alone table containing the text values and click Attribute Table.
- In the attribute table view, right-click the header of the new field created in Step 1 and click Calculate Field.
- In the Calculate Field window, for Expression Type, ensure Python 3 is selected.
- Depending on the number of delimiters, use one of the codes provided below to split the text values.
- If the text values only contain one delimiter, type the code provided below in the expression box. Replace 'Field Name' with the name of the field containing the text values, and replace <delimiter1> with the delimiter in the text values. In this example, the field name is 'Address' and the delimiter is '*'.
!Field Name!.split("<delimiter1>")[-1]
Note:
Do not remove the exclamation marks surrounding the field name.
- If the text values contain multiple delimiters, type the code provided below in the expression box. The replace() method is used to replace the different delimiters with a single common delimiter. Substitute <old_delimiter_n> with the delimiters to be replaced and substitute <delimiter1> with the common delimiter. In this example, the delimiters to be replaced are '-' and '/', and the common delimiter is '*'.
!Field Name!.replace("<old_delimiter_n>","<delimiter1>").replace("<old_delimiter_n>","<delimiter1>").split("<delimiter1>")[-1]
- Click Apply.
- Click OK to close the Calculate Field window.
The last values are split based on the delimiters and populated into the new field.