<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Split records of a field which are separated by a specific character in several columns in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002798#M59087</link>
    <description>&lt;P&gt;I haven't tested this so there's likely something wrong, but give it a try and let me know how it goes.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

fc = path_to_fc
# Get list of fields, ignoring ObjectID
# Assumes that all other fields are valid for the separated list values to go
fields = [f.name for f in arcpy.ListFields(fc) if f.type != "OID" or f.name != "OBJECTID"]
# Put the field with the sparated values at the end of the list
# so it's easy to identify.
sep_field = fields.pop(fields.index("test"))
fields.append(sep_field)
with arcpy.da.UpdateCursor(fc, fields) as cursor: 
    for row in cursor:
        # Make list of individual values
        # Assumes separators are always a comma (no space).
        sep_values = row[-1].split(",")
        # Make list of columns to receive values
        sep_columns = row[:-1]
        for i, value in enumerate(sep_values):
            # Put each value into a column.
            # Will yield IndexError if there are too many values for the columns.
            sep_columns[i] = value
            # Any additional columns that don't have a new value
            # will retain their original value (if any).
        # Put the original separated list of values
        # back with the new column values.
        row = sep_columns.append(sep_values)
        # Update the row in the table
        cursor.updateRow(row)&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 18 Nov 2020 23:46:18 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2020-11-18T23:46:18Z</dc:date>
    <item>
      <title>Split records of a field which are separated by a specific character in several columns</title>
      <link>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002298#M59080</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I would like to ask how can I split the entries of a field which are separated by commas, into new columns. Because comma-separated partitions can be too many (maybe 50) it is difficult to do it manually with .split () for each column separately.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 20:40:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002298#M59080</guid>
      <dc:creator>GeorgiosFot</dc:creator>
      <dc:date>2020-11-17T20:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Split records of a field which are separated by a specific character in several columns</title>
      <link>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002307#M59081</link>
      <description>&lt;P&gt;Have you used model builder before? Even if not, this guide seems to be a good walkthrough:&lt;/P&gt;&lt;P&gt;&lt;A href="https://resources.esri.ca/getting-technical/delimit-your-data-in-modelbuilder" target="_blank"&gt;https://resources.esri.ca/getting-technical/delimit-your-data-in-modelbuilder&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 20:59:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002307#M59081</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-11-17T20:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Split records of a field which are separated by a specific character in several columns</title>
      <link>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002729#M59083</link>
      <description>&lt;P&gt;I see that there can be a variable number of values in the list. Will they always be sequential? In other words, if it skips a column, will there be an empty value? Like a,b,c,,e,f&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 22:00:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002729#M59083</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2020-11-18T22:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Split records of a field which are separated by a specific character in several columns</title>
      <link>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002741#M59084</link>
      <description>&lt;P&gt;You're right, I believe this will not respect the order i.e. a field could contain any records depending on order or amount of delimited records.&lt;/P&gt;&lt;P&gt;My go-to would be to script it, do you have any scripting experience?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 22:09:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002741#M59084</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-11-18T22:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Split records of a field which are separated by a specific character in several columns</title>
      <link>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002798#M59087</link>
      <description>&lt;P&gt;I haven't tested this so there's likely something wrong, but give it a try and let me know how it goes.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

fc = path_to_fc
# Get list of fields, ignoring ObjectID
# Assumes that all other fields are valid for the separated list values to go
fields = [f.name for f in arcpy.ListFields(fc) if f.type != "OID" or f.name != "OBJECTID"]
# Put the field with the sparated values at the end of the list
# so it's easy to identify.
sep_field = fields.pop(fields.index("test"))
fields.append(sep_field)
with arcpy.da.UpdateCursor(fc, fields) as cursor: 
    for row in cursor:
        # Make list of individual values
        # Assumes separators are always a comma (no space).
        sep_values = row[-1].split(",")
        # Make list of columns to receive values
        sep_columns = row[:-1]
        for i, value in enumerate(sep_values):
            # Put each value into a column.
            # Will yield IndexError if there are too many values for the columns.
            sep_columns[i] = value
            # Any additional columns that don't have a new value
            # will retain their original value (if any).
        # Put the original separated list of values
        # back with the new column values.
        row = sep_columns.append(sep_values)
        # Update the row in the table
        cursor.updateRow(row)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 18 Nov 2020 23:46:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-of-a-field-which-are-separated-by-a/m-p/1002798#M59087</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2020-11-18T23:46:18Z</dc:date>
    </item>
  </channel>
</rss>

