HOW TO

Split an attribute field's values into different fields based on a delimiter in ArcGIS Pro

Last Published: August 5, 2022

Summary

In ArcGIS Pro, an attribute field may contain values separated by delimiters, and it is sometimes necessary to separate the values into different fields for data analysis purposes. Instead of converting the feature class to an Excel file and splitting the field using the Convert Text to Columns Wizard in Microsoft Excel, the same results can be achieved using ArcPy in ArcGIS Pro.

The ArcPy script provided in this article involves creating new fields to populate the results, splitting the string values based on a delimiter, and removing leading and trailing blank spaces from the results. In this example, the Address field is used to split the address components, separated by commas, into three separate fields.

The table view and the Address field.

Procedure

  1. In ArcGIS Pro, on the Analysis tab, click the drop-down arrow next to Python, and click Python Window.
  2. Import the necessary module.
import arcpy
  1. Set the path to the feature class containing the attribute field.
fc = r"<feature class path>"
  1. Define the new fields to populate the split values.
arcpy.AddField_management(fc, "<new field 1>", "TEXT")
arcpy.AddField_management(fc, "<new field 2>", "TEXT")
arcpy.AddField_management(fc, "<new field 3>", "TEXT")
  1. Define the parameters for the UpdateCursor() function to iterate through the feature class to split the string value based on a delimiter and remove leading and trailing blank spaces in the new fields.
with arcpy.da.UpdateCursor(fc, ["<field to split>", "<new field 1>", "<new field 2>", "<new field 3>"]) as cursor:
    for row in cursor:
        row[1] = row[0].split("<delimiter>")[0]
        row[2] = row[0].split("<delimiter>")[1]
        row[3] = row[0].split("<delimiter>")[2]

        row=[i.strip() if i is not None else None for i in row] 
        cursor.updateRow(row)

The following shows an example of the full script.

import arcpy

fc = r"C:\Users\User\Documents\ArcGIS\Projects\delimited\delimited.gdb\Point_1"

arcpy.AddField_management(fc, "First", "TEXT")
arcpy.AddField_management(fc, "Second", "TEXT")
arcpy.AddField_management(fc, "Third", "TEXT")

with arcpy.da.UpdateCursor(fc, ["Address", "First", "Second", "Third"]) as cursor:
    for row in cursor:
        row[1] = row[0].split(",")[0]
        row[2] = row[0].split(",")[1]
        row[3] = row[0].split(",")[2]

        row=[i.strip() if i is not None else None for i in row]
        cursor.updateRow(row)
  1. Place the cursor at the end of the script, and press Enter on the keyboard twice.
  2. In the Contents pane, right-click the feature class and click Attribute Table. The addresses are split and populated in the new fields based on the delimiter.
The table view with the Address field and populated the three new fields, First, Second, and Third.

Article ID: 000028137

Software:
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 x

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options