<?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: How to Concatenate Fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486676#M37973</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks! This looks promising. I inserted my values and am getting an ambiguous Runtime Error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 10, in &amp;lt;module&amp;gt;
&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\__init__.py", line 1133, in SearchCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; return gp.searchCursor(dataset, where_clause, spatial_reference, fields, sort_fields)
&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 359, in searchCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; self._gp.SearchCursor(*gp_fixargs(args, True)))
RuntimeError: ERROR 999999: Error executing function.&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 21:25:58 GMT</pubDate>
    <dc:creator>CraigMcDade</dc:creator>
    <dc:date>2021-12-11T21:25:58Z</dc:date>
    <item>
      <title>How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486672#M37969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have an attribute table with approx 1000 records. There are two Fields I care about: Name and Pg_Number (see attached pic)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to consolidate the fields so that I received an output or a new field that combines the Pg_Number field based on the Name Field&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ex.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my head its something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;
if [Name] = "Orange Lake" then [Pg_Number] = 5, 6, 7, 8, 9, 10...
if [Name] = "Green Lake" then [Pg_Number] = 11, 12, 13, 14, 15..."
and so on...
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I haven't had much experience with Python but I'm trying to build a model/script and I'm getting stuck on how to do this field calc/consolidation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be appreciated.[ATTACH=CONFIG]21511[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 17:52:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486672#M37969</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2013-02-06T17:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486673#M37970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't understand fully what you are trying to do. Can you give an example of the desired output for the first few rows of the data you posted?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 19:14:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486673#M37970</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-02-06T19:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486674#M37971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In my data the NAME field refers to Fire Station Boundaries and the Pg_Number refers to the page in the mapbook. I'm trying to convert or create a table so that all pages that are within each boundary are listed together, separated by a comma.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So instead of the table as it was originally uploaded, you would get a result of:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Name: Orange Lake 
Pg_Number: 5, 6, 7, 8, 9, 10, 11, 12, 13, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 47
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are 33 unique NAME attributes. I need to create a mapbook of each NAME &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The goal after getting this would be then to take the page list and push it to export to pdf those pages.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I went through the process manually yesterday and it was awful. I wound up taking that table, opening it in excel, downloading KuTools, using their combine tool to create the page listings (manually selecting which cells), then individually taking those page ranges and taking it back into ArcMap MapLogic tools and exporting from there. 10 hours of click.click.click. ugh.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I figure there has to be an easier/more efficient way than that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:25:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486674#M37971</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2021-12-11T21:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486675#M37972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I haven't tested this exactly but it should get you on the right path. It cursors through your initial table creating a dictionary of key, list values. Then it uses an insert cursor to basically inject those dictionary keys and lists into a new table using the same field names. You'd have to either create the new table or add that aspect to the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

table = # source_table
new_table = # new table
keyField = 'Name'
valField = 'Pg_number'

tableDict = {}

for row in arcpy.SearchCursor(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; tableDict.setdefault(row.getValue(keyField), []).append(row.getValue(valField))

insertCursor = arcpy.InsertCursor(new_table)
for key, val in tableDict.iteritems():
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = insertCursor.newRow()
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(keyField, key)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(valField, ', '.join(val))
&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor.insertRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:25:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486675#M37972</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T21:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486676#M37973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks! This looks promising. I inserted my values and am getting an ambiguous Runtime Error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 10, in &amp;lt;module&amp;gt;
&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\__init__.py", line 1133, in SearchCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; return gp.searchCursor(dataset, where_clause, spatial_reference, fields, sort_fields)
&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 359, in searchCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; self._gp.SearchCursor(*gp_fixargs(args, True)))
RuntimeError: ERROR 999999: Error executing function.&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:25:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486676#M37973</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2021-12-11T21:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486677#M37974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That could be from your target string field you are concatenating all the values together in is not long enough. Or it could be something else. Do you have a join on your table by any chance?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 12:02:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486677#M37974</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-02-07T12:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486678#M37975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The table is a result of a spatial join that I performed, but there are no active joins from external tables.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 12:11:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486678#M37975</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2013-02-07T12:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486679#M37976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try changing the search cursor to these lines.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;tableDict = {}
arcpy.MakeTableView_management(table, tempTable)
with arcpy.da.SearchCursor(tempTable, [keyField, valField]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tableDict.setdefault(row[0], []).append(row[1])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486679#M37976</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T21:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486680#M37977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;that gets me:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 9, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NameError: name 'tempTable' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate your time and help. I'm also getting an error that my dbf file doesn't exist, so I converted it to an xlsx and don't get that error. Not sure if that matters, and for the new table I just created an empty excel spreadsheet. That could be wrong too. As you can tell. I'm new to this. thanks for your patience.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 12:54:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486680#M37977</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2013-02-07T12:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486681#M37978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ah yes you'd need to declare that. Something like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;tempTable = r'\\in_memory\temp_table'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also you'll want to make it a dbf or fgdb table, something Arc can read easily. Excel is not great for that. You'll also have to create this before you run your script. Make sure the field you want to all the values in is a long enough string field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 13:14:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486681#M37978</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-02-07T13:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486682#M37979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;well it is working and creating the table view. but for whatever reason it isn't reading my new_table portion correctly&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have inputed:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
new_table = "c:\users\craig.mcdade\table.dbf" # new table
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but getting this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IOError: "c:\users\craig.mcdade able.dbf" does not exist&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;as you can see, it is not recognizing the \t in the file structure?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486682#M37979</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2021-12-11T21:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486683#M37980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes because \t is a tab. You need to format paths like this when using single backslashes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;new_table = r"c:\users\craig.mcdade\table.dbf"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can read this for more information on string literals.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2/reference/lexical_analysis.html#string-literals"&gt;http://docs.python.org/2/reference/lexical_analysis.html#string-literals&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 13:59:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486683#M37980</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-02-07T13:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486684#M37981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;again you've been quite helpful and patient with my lack of understanding. I'm getting a similar error as with the above SearchCursor error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 15, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\__init__.py", line 1180, in InsertCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return gp.insertCursor(dataset, spatial_reference)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 369, in insertCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self._gp.InsertCursor(*gp_fixargs(args, True)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is almost identical to the previous error, so using your example I made an attempt to fix this one with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.insertCursor(new_table)
... with arcpy.da.InsertCursor(key, val in tableDict.iteritems()) as cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = insertCursor.newRow()
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(keyField, key)
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(valField, ', '.join(val))
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor.insertRow(row)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I at least close?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486684#M37981</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2021-12-11T21:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486685#M37982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The insert cursor is a little different than the search cursor. To use the .da insert cursor you want to do something like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;insertCursor = arcpy.da.InsertCursor(os.path.join(outPath, new_table), [keyField, valField])

for key, val in tableDict.iteritems():
&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor.insertRow((key, ', '.join(val)))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486685#M37982</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T21:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486686#M37983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;well. I'm close now. The current code is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
&amp;nbsp; 
table = r"c:\users\craig.mcdade\GridforPython.dbf" # source_table
new_table = r"c:\users\craig.mcdade\table.dbf" # new table
tempTable = r'\\in_memory\temp_table'
outPath = r'\\in_memory\outPath'
keyField = 'NAME'
valField = 'Pg_Number'
&amp;nbsp; 
tableDict = {}
arcpy.MakeTableView_management(table, tempTable)
with arcpy.da.SearchCursor(tempTable, [keyField, valField]) as cursor:
&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; tableDict.setdefault(row[0], []).append(row[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
open("new_table","w")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
insertCursor = arcpy.da.InsertCursor(os.path.join(outPath, new_table), [keyField, valField])

for key, val in tableDict.iteritems():
&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor.insertRow((key, ', '.join(val)))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was getting a Runtime Error: cannot open 'c:\...'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so I added the open("new_table","w") line&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;now I get a Runtime Error of Permission denied: 'new_table'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have allowed full permissions on the dbf file so I'm not sure why it isn't allowing it to open.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486686#M37983</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2021-12-11T21:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486687#M37984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Don't open the table that way, that is for a different kind of accessing. The cursor handles all the back end you need. Your outPath variable should be to a place on disk, not in memory. Your new_table variable should just be the name of the table not the path.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
import arcpy

table = r"c:\users\craig.mcdade\GridforPython.dbf" # source_table
new_table = r"table.dbf" # new table name + extension only
tempTable = r"\\in_memory\temp_table"
outPath = r"c:\users\craig.mcdade" # path to output location on disk
keyField = 'NAME'
valField = 'Pg_Number'

tableDict = {}
arcpy.MakeTableView_management(table, tempTable)
with arcpy.da.SearchCursor(tempTable, [keyField, valField]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tableDict.setdefault(row[0], []).append(row[1])

insertCursor = arcpy.da.InsertCursor(os.path.join(outPath, new_table), [keyField, valField])

for key, val in tableDict.iteritems():
&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor.insertRow((key, ', '.join(val)))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486687#M37984</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T21:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486688#M37985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks for the tip on the open statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;still getting the same runtime error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 17, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: cannot open 'c:\users\craig.mcdade\table.dbf'&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 18:23:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486688#M37985</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2013-02-07T18:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486689#M37986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you open it in ArcCatalog? Or are you leaving it open somewhere while it is trying to be accessed? I'd recommend closing any open ArcGIS instances before running it to make sure.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 18:27:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486689#M37986</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-02-07T18:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486690#M37987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;once again good call. my file was open and locked by arcmap when i used the incorrect open call&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;new error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 20, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: sequence item 0: expected string, int found&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 18:50:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486690#M37987</guid>
      <dc:creator>CraigMcDade</dc:creator>
      <dc:date>2013-02-07T18:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Concatenate Fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486691#M37988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oh yes I had forgotten it was a list of ints you were pulling here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try replacing this as the last line. The 'for key, val...' line is there just for reference it is the same.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for key, val in tableDict.iteritems():
&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor.insertRow((key, ', '.join(str(item) for item in val))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-concatenate-fields/m-p/486691#M37988</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T21:26:17Z</dc:date>
    </item>
  </channel>
</rss>

