HOW TO
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.
import arcpy
fc = r"<feature class path>"
arcpy.AddField_management(fc, "<new field 1>", "TEXT") arcpy.AddField_management(fc, "<new field 2>", "TEXT") arcpy.AddField_management(fc, "<new field 3>", "TEXT")
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)
Get help from ArcGIS experts
Download the Esri Support App