<?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 comma separated values to multiple rows in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396981#M80488</link>
    <description>Always the same&lt;BR /&gt;</description>
    <pubDate>Sat, 16 Mar 2024 22:08:21 GMT</pubDate>
    <dc:creator>Ed_</dc:creator>
    <dc:date>2024-03-16T22:08:21Z</dc:date>
    <item>
      <title>Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396514#M80402</link>
      <description>&lt;P&gt;Based on the sample data below I am trying to split each comma separated value in `MUNICIPALI` column to a new as shown in desired output. However, I am getting an error that `Projects_City` cannot open, it does not exist, but then I thought line 6 and onwards will create it. How can I fix this issue? On a side note, the comma separated values are a lot more than the sample data. For, example, one of them rows have 18 or something comma separated values so, will line 10 work for that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
# Import the surtax projects geodatabase table subset
in_df = r"O:\MyProject.gdb\Projects_City"
out_df = r"O:\MyProject.gdb\Projects_City_Updated" # Doesn't exist, expect it to be created in line 6
fldlst = ["OBJECTID", "PRJID", "MUNICIPALI"]
with arcpy.da.InsertCursor(out_df, fldlst) as insertCursor:
    with arcpy.da.SearchCursor(in_df, fldlst) as searchCursor:
        for row in searchCursor:
            for attrbPart in row[3].split(","):
                insertCursor.insertRow(( row[0], row[1], row[2], attrbPart))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "o:\path\SplitCommas2Row.py", line 6, in &amp;lt;module&amp;gt;
    with arcpy.da.InsertCursor(out_df, fldlst) as insertCursor:
RuntimeError: cannot open 'O:\MyProject.gdb\Projects_City_Updated'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;After creating the table, please see updated code below, I am getting the following error, how can I fix it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
# Import the surtax projects geodatabase table subset
in_df = r"O:\MyProject.gdb\Projects_City"
arcpy.management.CreateTable(
    out_path=r"O:\MyProject.gdb",
    out_name="Projects_City_Updated",
    template=in_df,
    config_keyword="",
    out_alias=""
)

out_df = r"O:\MyProject.gdb\Projects_City_Updated"

fldlst = ["PRJTID", "MUNICIPALI", "ZIPCODE"]

with arcpy.da.InsertCursor(out_df, fldlst) as insertCursor:
    with arcpy.da.SearchCursor(in_df, fldlst) as searchCursor:
        for row in searchCursor:
            for attrbPart in row[3].split(","):
                insertCursor.insertRow(( row[0], row[1], row[2], attrbPart))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "o:\SplitCommas2Row.py", line 22, in &amp;lt;module&amp;gt;
    for attrbPart in row[3].split(","):
IndexError: tuple index out of range&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample Data:&lt;/P&gt;&lt;TABLE width="331px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="88px"&gt;OBJECTID&lt;/TD&gt;&lt;TD width="62px"&gt;PRJTID&lt;/TD&gt;&lt;TD width="101px"&gt;MUNICIPALI&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;ZIPCODE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;1&lt;/TD&gt;&lt;TD width="62px"&gt;1&lt;/TD&gt;&lt;TD width="101px"&gt;A&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;2&lt;/TD&gt;&lt;TD width="62px"&gt;2&lt;/TD&gt;&lt;TD width="101px"&gt;A, B&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1,2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;3&lt;/TD&gt;&lt;TD width="62px"&gt;3&lt;/TD&gt;&lt;TD width="101px"&gt;A, B, C&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1,2,3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;4&lt;/TD&gt;&lt;TD width="62px"&gt;4&lt;/TD&gt;&lt;TD width="101px"&gt;A, B, C, D&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1,2,3,4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;5&lt;/TD&gt;&lt;TD width="62px"&gt;5&lt;/TD&gt;&lt;TD width="101px"&gt;A&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;6&lt;/TD&gt;&lt;TD width="62px"&gt;6&lt;/TD&gt;&lt;TD width="101px"&gt;C&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output:&lt;/P&gt;&lt;TABLE width="331px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="88px"&gt;OBJECTID&lt;/TD&gt;&lt;TD width="62px"&gt;PRJTID&lt;/TD&gt;&lt;TD width="101px"&gt;MUNICIPALI&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;ZIPCODE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;1&lt;/TD&gt;&lt;TD width="62px"&gt;1&lt;/TD&gt;&lt;TD width="101px"&gt;A&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;2&lt;/TD&gt;&lt;TD width="62px"&gt;2&lt;/TD&gt;&lt;TD width="101px"&gt;A&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;3&lt;/TD&gt;&lt;TD width="62px"&gt;2&lt;/TD&gt;&lt;TD width="101px"&gt;B&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;4&lt;/TD&gt;&lt;TD width="62px"&gt;3&lt;/TD&gt;&lt;TD width="101px"&gt;A&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;5&lt;/TD&gt;&lt;TD width="62px"&gt;3&lt;/TD&gt;&lt;TD width="101px"&gt;B&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;6&lt;/TD&gt;&lt;TD width="62px"&gt;3&lt;/TD&gt;&lt;TD width="101px"&gt;C&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;7&lt;/TD&gt;&lt;TD width="62px"&gt;4&lt;/TD&gt;&lt;TD width="101px"&gt;A&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;8&lt;/TD&gt;&lt;TD width="62px"&gt;4&lt;/TD&gt;&lt;TD width="101px"&gt;B&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;9&lt;/TD&gt;&lt;TD width="62px"&gt;4&lt;/TD&gt;&lt;TD width="101px"&gt;C&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;10&lt;/TD&gt;&lt;TD width="62px"&gt;4&lt;/TD&gt;&lt;TD width="101px"&gt;D&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;11&lt;/TD&gt;&lt;TD width="62px"&gt;5&lt;/TD&gt;&lt;TD width="101px"&gt;A&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="88px"&gt;12&lt;/TD&gt;&lt;TD width="62px"&gt;6&lt;/TD&gt;&lt;TD width="101px"&gt;C&lt;/TD&gt;&lt;TD width="80px" height="20"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 15 Mar 2024 16:17:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396514#M80402</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-15T16:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396520#M80403</link>
      <description>&lt;P&gt;Try creating the table first and see if it works.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 13:09:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396520#M80403</guid>
      <dc:creator>BobBooth1</dc:creator>
      <dc:date>2024-03-15T13:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396525#M80404</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/95621"&gt;@BobBooth1&lt;/a&gt;&amp;nbsp;thank you for the quick response, after creating the table, I am getting a tuple error now, please see the updated post, thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 13:30:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396525#M80404</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-15T13:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396531#M80405</link>
      <description>&lt;P&gt;I think you want "row[2]" here:&lt;/P&gt;&lt;PRE&gt;for attrbPart in row[3].split(","):&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 13:44:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396531#M80405</guid>
      <dc:creator>BobBooth1</dc:creator>
      <dc:date>2024-03-15T13:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396538#M80406</link>
      <description>&lt;P&gt;Okay, so a few things:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;As a general rule,&amp;nbsp;&lt;STRONG&gt;don't&lt;/STRONG&gt; nest Cursors in each other.&amp;nbsp; The efficiency generally takes a nosedive.&lt;UL&gt;&lt;LI&gt;I think with an InsertCursor it's less of an issue, but it's still a better practice to separate them.&amp;nbsp; If this had been an UpdateCursor, you would have run through the entire table once for&amp;nbsp;&lt;EM&gt;every row on the table&lt;/EM&gt;.&amp;nbsp; (Meaning for your sample of 6 records, it would've made 36 passes through the table)&lt;/LI&gt;&lt;LI&gt;I would first run that SearchCursor and write the necessary data to a dictionary or something similar, and then run the InsertCursor to do your operations.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;In line 22, you're assuming your tuple has 4 entries.&amp;nbsp; In line 23, you reference 3.&amp;nbsp; Your field list and your sample data indicate you only have 2 entries to work with in the tuple.&lt;UL&gt;&lt;LI&gt;SearchCursor returns a tuple of the same length as your field list parameter, which lists the values in the same order as those fields they came from.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;In your sample data, you have items delimited by&amp;nbsp;&lt;STRONG&gt;comma and space&lt;/STRONG&gt; (", "), but in line 22, you assume they're delimited by&amp;nbsp;&lt;STRONG&gt;comma only&lt;/STRONG&gt; (",").&amp;nbsp; I'm assuming this is just a formatting thing in how you typed up the post here, but be careful of differences like that.&amp;nbsp; Line 27 of my code below assumes there are spaces after the commas.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
# Import the surtax projects geodatabase table subset
in_df = r"O:\MyProject.gdb\Projects_City"
arcpy.management.CreateTable(
    out_path=r"O:\MyProject.gdb",
    out_name="Projects_City_Updated",
    template=in_df,
    config_keyword="",
    out_alias=""
)

out_df = r"O:\MyProject.gdb\Projects_City_Updated"

fldlst = ["PRJTID", "MUNICIPALI"]

munis = {}

with arcpy.da.SearchCursor(in_df, fldlst) as sc:
    for prj, muni in sc:
        # NOTE: This assumes the values in PRJTID are unique.  If any repeat
        #  then you'll need to check the munis dictionary to see if you've
        #  seen this particular prjtid before, and append your muni results 
        #  to the existing record, if you have one.
        munis[prj] = muni.split(', ')

with arcpy.da.InsertCursor(out_df, fldlst) as ic:
    for prj in munis:
        for muni in munis[prj]:
            ic.insertRow((prj, muni))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 14:02:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396538#M80406</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2024-03-15T14:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396549#M80407</link>
      <description>&lt;P&gt;Worked like charm, thank you so much&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 14:24:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396549#M80407</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-15T14:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396639#M80419</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/569244"&gt;@MErikReedAugusta&lt;/a&gt;&amp;nbsp;can you please look at the modified sample data. It seems like I would also have to split the `ZIPCODE` column as well. How can I split both `MUNICIPALI` and `ZIPCODE` at the same time? Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 16:16:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396639#M80419</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-15T16:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396663#M80423</link>
      <description>&lt;P&gt;That depends on how those two fields should interact &amp;amp; combine.&lt;/P&gt;&lt;P&gt;Your sample data seems to be missing some potential combinations for PRJ 2, for example:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;PRJ&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;MUN&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;ZIP&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;A, B&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;1, 2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would expect the following:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;PRJ&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;MUN&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;ZIP&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;A&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;B&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;A&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;B&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;(Your sample data is missing the second &amp;amp; fourth rows.)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;munis = {}
# Search Cursor here; Fields [PRJTID, MUNICPALI, ZIPCODE]:
for prj, mun, zip in cursor:
    munvals = mun.split(', ')
    zipvals = zip.split(', ')

    joinvals = []

    for munval in munvals:
        for zipval in zipvals:
            joinval = f'{munval}|{zipval}'
            joinvals.append(joinval)
            del joinval

    munis[prj] = joinvals
    del joinvals, munvals, zipvals&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Alternately,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I notice your sample data also has the same number of items for MUN &amp;amp; ZIP, though.&amp;nbsp; While it's not going to always be true in the real world, if your sample data guarantees a 1:1 match of municipality to ZIP, then you could do the merging that way, before you run the split.&amp;nbsp; If that's the case, you can replace the for loops at Line 9-13 with the snippet below.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; Because this assumes a 1:1 match, if you have 5 values in one column and 4 in the other, it'll just ignore that 5th value entirely.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;index = 0
while index &amp;lt; len(munvals) and index &amp;lt; len(zipvals):
    joinval = f'{munvals[index]}|{zipvals[index]}'
    joinvals.append(joinval)
    del joinval&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 16:49:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396663#M80423</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2024-03-15T16:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396669#M80426</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/569244"&gt;@MErikReedAugusta&lt;/a&gt;&amp;nbsp;&amp;nbsp;Thank you so much&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&amp;nbsp;For the new snippet I am getting warning message that `cursor` is not defined. Do I need to define `cursor` earlier in the code?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 19:19:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396669#M80426</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-15T19:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396673#M80428</link>
      <description>&lt;P&gt;Related:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-dashboards-questions/arcade-split-comma-delimited-value-into-multiple/m-p/1105537" target="_self"&gt;Arcade Split comma delimited value into multiple rows, keeping row details&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Idea:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/gp-tool-to-split-field-with-comma-delimited-values/idi-p/1396751" target="_self"&gt;GP tool to split field with comma-delimited values into multiple rows&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 18:59:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396673#M80428</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2024-03-15T18:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396755#M80446</link>
      <description>&lt;P&gt;What kind of geodatabase?&lt;/P&gt;&lt;P&gt;If it's an enterprise or mobile geodatabase, it could possibly be done with SQL in a query layer or database view. Maybe using a recursive WITH clause or a database-specific mechanism.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 19:00:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396755#M80446</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2024-03-15T19:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396761#M80449</link>
      <description>&lt;P&gt;Hi Bud, thank you for the suggestion, I prefer Python since I will be automating the script and what I am doing right now is just the beginning of the script.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 19:14:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396761#M80449</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-15T19:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396766#M80451</link>
      <description>&lt;P&gt;Even still, using a permanent database view in your Python script could simplify your script.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 19:21:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396766#M80451</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2024-03-15T19:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396788#M80458</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/569244"&gt;@MErikReedAugusta&lt;/a&gt;&amp;nbsp;so I tried adding the cursor using the `with` statement and now I am getting the following error. Also, I don't if indented the `while` loop correctly or not.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;while index &amp;lt; len(munvals) and index &amp;lt; len(zipvals):
NameError: name 'munvals' is not defined&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
# Import the surtax projects geodatabase table subset
in_df = r"O:\MyProject.gdb\Projects_City"
arcpy.management.CreateTable(
    out_path=r"O:\MyProject.gdb",
    out_name="Projects_City_Updated",
    template=in_df,
    config_keyword="",
    out_alias=""
)

out_df = r"O:\MyProject.gdb\Projects_City_Updated"

fldlst = ["PRJTID", "MUNICIPALI", "ZIPCODE"]

munis = {}
# Search Cursor here; Fields [PRJTID, MUNICPALI, ZIPCODE]:
with arcpy.da.SearchCursor(in_df, fldlst) as cursor:
    for prj, mun, zip in cursor:
        munvals = mun.split(',')
        zipvals = zip.split(',')

        joinvals = []

    index = 0
    while index &amp;lt; len(munvals) and index &amp;lt; len(zipvals):
        joinval = f'{munvals[index]}|{zipvals[index]}'
        joinvals.append(joinval)
        del joinval

        munis[prj] = joinvals
        del joinvals, munvals, zipvals&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 15 Mar 2024 19:53:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396788#M80458</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-15T19:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396813#M80468</link>
      <description>&lt;P&gt;Yeah,&amp;nbsp;looks like a few of the nested blocks didn't nest properly.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with ...
    for ...
        [Line 23-28]
        while ...
            [Line 30-32]
        munis[prj] ...
        del joinvals, ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Re: "cursor", looks like I threw you a curve ball by changing what I called the cursor from one script to another.&amp;nbsp; I was typing these off the top of my head earlier.&amp;nbsp; Your most recent code seems to call it correctly, so it looks like you figured it out.&lt;/P&gt;&lt;P&gt;I'm going to assume you're getting that error on your&amp;nbsp;&lt;EM&gt;second&lt;/EM&gt; time through that While statement.&amp;nbsp; Essentially, the way you have it indented, it uses the for loop to go through the entire database, and just keeps overwriting itself.&amp;nbsp; That means that it gets to the while loop on the last record in your database.&lt;/P&gt;&lt;P&gt;Then, it runs the while loop once, and logs the values from that last record.&amp;nbsp; But then line 35 deletes the variables that the while loop is looking for.&amp;nbsp; You ripped a stone out from the bottom of the wall, so it all came crashing down.&lt;/P&gt;&lt;P&gt;Fixing the indentation should fix the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With Python, try to think of things in logical blocks, like an outline you might write before starting a research paper.&amp;nbsp; The indentation is how you join blocks together.&amp;nbsp; Lines that start at the same indentation are part of the same "block".&amp;nbsp; If you scroll up through your code from the bottom, the first line you come to that's&amp;nbsp;&lt;EM&gt;less&lt;/EM&gt; indented is the start of that block.&lt;/P&gt;&lt;P&gt;So instead of the while block existing&amp;nbsp;&lt;EM&gt;inside&lt;/EM&gt; the for block, the way you have it indented makes it exist&amp;nbsp;&lt;EM&gt;beside&lt;/EM&gt; the for loop, which breaks the logic of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 20:47:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396813#M80468</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2024-03-15T20:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396980#M80487</link>
      <description>&lt;P&gt;Is the number of comma-separated values in MUNICIPALITY and ZIPCODE always the same?&lt;/P&gt;&lt;P&gt;For example, would&amp;nbsp;MUNICIPALITY ever have 1 value, but ZIPCODE has 2 values?&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 21:56:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396980#M80487</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2024-03-16T21:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396981#M80488</link>
      <description>Always the same&lt;BR /&gt;</description>
      <pubDate>Sat, 16 Mar 2024 22:08:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1396981#M80488</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-16T22:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1397042#M80492</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/554773"&gt;@Ed_&lt;/a&gt;, the updated code was close to working, you just need to use Python zip() function and change 2 lines:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
# Import the surtax projects geodatabase table subset
in_df = r"O:\MyProject.gdb\Projects_City"
arcpy.management.CreateTable(
    out_path=r"O:\MyProject.gdb",
    out_name="Projects_City_Updated",
    template=in_df,
    config_keyword="",
    out_alias=""
)

out_df = r"O:\MyProject.gdb\Projects_City_Updated"

fldlst = ["PRJTID", "MUNICIPALI", "ZIPCODE"]

with arcpy.da.InsertCursor(out_df, fldlst) as insertCursor:
    with arcpy.da.SearchCursor(in_df, fldlst) as searchCursor:
        for row in searchCursor:
            for z in zip(*(map(str.strip, str.split(i, ",")) for i in row[1:])):
                insertCursor.insertRow(row[0:1] + z)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 18:48:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1397042#M80492</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-03-19T18:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1397224#M80515</link>
      <description>&lt;P&gt;Good morning&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;worked like a charm thank you, the zip function makes things simpler.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 13:36:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1397224#M80515</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-18T13:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: Split comma separated values to multiple rows</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1397274#M80525</link>
      <description>&lt;P&gt;Good morning&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/569244"&gt;@MErikReedAugusta&lt;/a&gt;&amp;nbsp;thank you so much for elaborate guidance on this&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 14:48:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/split-comma-separated-values-to-multiple-rows/m-p/1397274#M80525</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-18T14:48:29Z</dc:date>
    </item>
  </channel>
</rss>

