<?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 Take values from one field, and concatenate into string field if IDs are the same. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194209#M65034</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fairly new to python. By no means a beginner, but I still have trouble with logic.&lt;/P&gt;&lt;P&gt;I'm currently trying to create a script which takes an ID field - if the IDs match up, then take the value from a name field, and concatenate together into a list, and fill out a concatenated list field (see table)&lt;/P&gt;&lt;P&gt;I know i will have to use a update_cursor and a counter etc. the logic for whatever reason is escaping me on how to assemble the python.&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Name&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Name_cancat&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;33&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;hello&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Hello, hi, bye&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;33&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;hi&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Hello, hi, bye&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;33&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;bye&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Hello, hi, bye&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;44&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;red&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Red, tan, blue&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;44&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;tan&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Red, tan, blue&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;44&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;blue&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Red, tan, blue&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;88&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;dog&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Dog, cat&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;88&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;cat&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Dog, cat&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it will be something like this (obviously missing a ton of code/logic)&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor("FC", ['ID', 'name', 'name_concat']) as cursor:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myList = []&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;myList.append(row[1])&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;row[2] = myList&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cursor.updateRow(row)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;any help pointing me to a resource would be greatly appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 20 Jul 2022 21:56:22 GMT</pubDate>
    <dc:creator>Server</dc:creator>
    <dc:date>2022-07-20T21:56:22Z</dc:date>
    <item>
      <title>Take values from one field, and concatenate into string field if IDs are the same.</title>
      <link>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194209#M65034</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fairly new to python. By no means a beginner, but I still have trouble with logic.&lt;/P&gt;&lt;P&gt;I'm currently trying to create a script which takes an ID field - if the IDs match up, then take the value from a name field, and concatenate together into a list, and fill out a concatenated list field (see table)&lt;/P&gt;&lt;P&gt;I know i will have to use a update_cursor and a counter etc. the logic for whatever reason is escaping me on how to assemble the python.&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;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P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;88&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;dog&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Dog, cat&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;88&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;cat&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Dog, cat&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it will be something like this (obviously missing a ton of code/logic)&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor("FC", ['ID', 'name', 'name_concat']) as cursor:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myList = []&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;myList.append(row[1])&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;row[2] = myList&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cursor.updateRow(row)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;any help pointing me to a resource would be greatly appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 20 Jul 2022 21:56:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194209#M65034</guid>
      <dc:creator>Server</dc:creator>
      <dc:date>2022-07-20T21:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Take values from one field, and concatenate into string field if IDs are the same.</title>
      <link>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194225#M65037</link>
      <description>&lt;P&gt;&amp;nbsp;I would make 2 passes through the table.&lt;/P&gt;&lt;P&gt;On pass one use a search cursor to create a python dict with each entry having the ID as the key and the list of string to be concatenated as the value.&lt;/P&gt;&lt;P&gt;On the second pass use an update cursor to&amp;nbsp; populate the name_cancat field in each record by using the value of the ID field to get the concatenated string from the dict.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 22:39:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194225#M65037</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-07-20T22:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Take values from one field, and concatenate into string field if IDs are the same.</title>
      <link>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194243#M65040</link>
      <description>&lt;P&gt;How about the Merge tool with a field map with a "," delimiter to combine the values, then a Join Field (Maybe faster for a large dataset.)&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 23:30:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194243#M65040</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2022-07-20T23:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Take values from one field, and concatenate into string field if IDs are the same.</title>
      <link>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194362#M65041</link>
      <description>&lt;P&gt;Python:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# use a SearchCursor to get ids and names
ids_and_names = [row for row in arcpy.da.SearchCursor("FC", ["ID", "name"])]

# use an UpdateCursor to update the concatenated names
with arcpy.da.UpdateCursor("FC", ["ID", "name_concat"]) as cursor:
    for row in cursor:
        names = [name for id, name in ids_and_names if id == row[0]]
        name_concat = ", ".join(names)
        cursor.updateRow([row[0], name_concat])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could also use the field calulator with Arcade:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// filter the dataset by the current id
var id = $feature.ID
var features_with_this_id = Filter($featureset, "ID = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/354972"&gt;@ID&lt;/a&gt;")
// extract names as array
var names = []
for(var f in features_with_this_id) {
    Push(names, f.name)
}
// return the concatenated array
return Concatenate(names, ", ")&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 21 Jul 2022 11:06:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1194362#M65041</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-07-21T11:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Take values from one field, and concatenate into string field if IDs are the same.</title>
      <link>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1195426#M65062</link>
      <description>&lt;P&gt;this is exactly what I needed! Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2022 15:08:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/take-values-from-one-field-and-concatenate-into/m-p/1195426#M65062</guid>
      <dc:creator>Server</dc:creator>
      <dc:date>2022-07-25T15:08:06Z</dc:date>
    </item>
  </channel>
</rss>

