<?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 Using Search and Insert Cursor to Find Certain Values and Replicate in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-search-and-insert-cursor-to-find-certain/m-p/1109489#M62722</link>
    <description>&lt;P&gt;I'm new to ArcPy and really coding in general.&lt;/P&gt;&lt;P&gt;I have three fields titled "Subcat_1", "Subcat_2", and "Subcat_3" all being used to categorize different themes of survey data that will then be used to create heat maps.&lt;/P&gt;&lt;P&gt;I am trying to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Use SearchCursor from the Data Access module to fetch an entire row if a value in Subcat_2 or Subcat_3 are not&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;null&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(This I have working already - I changed my&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;null&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;values to a string "Nothing")&lt;/LI&gt;&lt;LI&gt;Copy and insert that fetched row to the row below, where the populated value from Subcat_2 will replace the value in Subcat_1 (as that value is above)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I have attached screenshots of what this workflow looks like in Excel&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Initial Table&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_9-1634768230773.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25686iCE935DACA7E24011/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_9-1634768230773.png" alt="WillemVan_Riet1_9-1634768230773.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Find value that is not empty&lt;SPAN&gt;&amp;nbsp;in Subcategory_2&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_10-1634768308907.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25687iAA0476535A7FE66E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_10-1634768308907.png" alt="WillemVan_Riet1_10-1634768308907.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Copy that row&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_11-1634768328601.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25688i0134670116EF2677/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_11-1634768328601.png" alt="WillemVan_Riet1_11-1634768328601.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Insert into row below&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_12-1634768355244.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25689i5AED0FE723FB93B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_12-1634768355244.png" alt="WillemVan_Riet1_12-1634768355244.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Have the value in Subcat_2 replace the duplicated value in Subcat_1&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_13-1634768394312.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25690i1325642C869E63BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_13-1634768394312.png" alt="WillemVan_Riet1_13-1634768394312.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Since I am inserting a row from the same feature class, the length, schema, geometry is all the same.&lt;/P&gt;&lt;P&gt;The version of some code that somewhat works is below (this is attempting to look for any unique values in Subcat_3, copying the row, and inserting them into Subcat_2):&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;# A list of values that will be used to construct new rows&lt;/SPAN&gt;

values = [row[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;] &lt;SPAN class=""&gt;for&lt;/SPAN&gt; row &lt;SPAN class=""&gt;in&lt;/SPAN&gt; arcpy.da.SearchCursor(social_layer, fieldnames)]
&lt;SPAN class=""&gt;#social_layer is the feature class I am working on&lt;/SPAN&gt;
&lt;SPAN class=""&gt;#fieldnames is the query for "Subcat_3"&lt;/SPAN&gt;

uniqueValues = &lt;SPAN class=""&gt;set&lt;/SPAN&gt;(values)

&lt;SPAN class=""&gt;# # Open an InsertCursor&lt;/SPAN&gt;
cursor = arcpy.da.InsertCursor(social_layer,
                           [&lt;SPAN class=""&gt;'Subcat_2'&lt;/SPAN&gt;])
&lt;SPAN class=""&gt;for&lt;/SPAN&gt; row &lt;SPAN class=""&gt;in&lt;/SPAN&gt; values:
    &lt;SPAN class=""&gt;if&lt;/SPAN&gt; row != &lt;SPAN class=""&gt;'Nothing'&lt;/SPAN&gt;:
        cursor.insertRow([row]) &lt;SPAN class=""&gt;#have to insert a list not a single value&lt;/SPAN&gt;

&lt;SPAN class=""&gt;# Delete cursor object&lt;/SPAN&gt;
&lt;SPAN class=""&gt;del&lt;/SPAN&gt; cursor&lt;/PRE&gt;&lt;P&gt;When I run the code I just break the layer&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Oct 2021 22:22:56 GMT</pubDate>
    <dc:creator>WillemVan_Riet1</dc:creator>
    <dc:date>2021-10-20T22:22:56Z</dc:date>
    <item>
      <title>Using Search and Insert Cursor to Find Certain Values and Replicate</title>
      <link>https://community.esri.com/t5/python-questions/using-search-and-insert-cursor-to-find-certain/m-p/1109489#M62722</link>
      <description>&lt;P&gt;I'm new to ArcPy and really coding in general.&lt;/P&gt;&lt;P&gt;I have three fields titled "Subcat_1", "Subcat_2", and "Subcat_3" all being used to categorize different themes of survey data that will then be used to create heat maps.&lt;/P&gt;&lt;P&gt;I am trying to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Use SearchCursor from the Data Access module to fetch an entire row if a value in Subcat_2 or Subcat_3 are not&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;null&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(This I have working already - I changed my&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;null&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;values to a string "Nothing")&lt;/LI&gt;&lt;LI&gt;Copy and insert that fetched row to the row below, where the populated value from Subcat_2 will replace the value in Subcat_1 (as that value is above)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I have attached screenshots of what this workflow looks like in Excel&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Initial Table&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_9-1634768230773.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25686iCE935DACA7E24011/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_9-1634768230773.png" alt="WillemVan_Riet1_9-1634768230773.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Find value that is not empty&lt;SPAN&gt;&amp;nbsp;in Subcategory_2&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_10-1634768308907.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25687iAA0476535A7FE66E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_10-1634768308907.png" alt="WillemVan_Riet1_10-1634768308907.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Copy that row&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_11-1634768328601.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25688i0134670116EF2677/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_11-1634768328601.png" alt="WillemVan_Riet1_11-1634768328601.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Insert into row below&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_12-1634768355244.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25689i5AED0FE723FB93B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_12-1634768355244.png" alt="WillemVan_Riet1_12-1634768355244.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Have the value in Subcat_2 replace the duplicated value in Subcat_1&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WillemVan_Riet1_13-1634768394312.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25690i1325642C869E63BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WillemVan_Riet1_13-1634768394312.png" alt="WillemVan_Riet1_13-1634768394312.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Since I am inserting a row from the same feature class, the length, schema, geometry is all the same.&lt;/P&gt;&lt;P&gt;The version of some code that somewhat works is below (this is attempting to look for any unique values in Subcat_3, copying the row, and inserting them into Subcat_2):&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;# A list of values that will be used to construct new rows&lt;/SPAN&gt;

values = [row[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;] &lt;SPAN class=""&gt;for&lt;/SPAN&gt; row &lt;SPAN class=""&gt;in&lt;/SPAN&gt; arcpy.da.SearchCursor(social_layer, fieldnames)]
&lt;SPAN class=""&gt;#social_layer is the feature class I am working on&lt;/SPAN&gt;
&lt;SPAN class=""&gt;#fieldnames is the query for "Subcat_3"&lt;/SPAN&gt;

uniqueValues = &lt;SPAN class=""&gt;set&lt;/SPAN&gt;(values)

&lt;SPAN class=""&gt;# # Open an InsertCursor&lt;/SPAN&gt;
cursor = arcpy.da.InsertCursor(social_layer,
                           [&lt;SPAN class=""&gt;'Subcat_2'&lt;/SPAN&gt;])
&lt;SPAN class=""&gt;for&lt;/SPAN&gt; row &lt;SPAN class=""&gt;in&lt;/SPAN&gt; values:
    &lt;SPAN class=""&gt;if&lt;/SPAN&gt; row != &lt;SPAN class=""&gt;'Nothing'&lt;/SPAN&gt;:
        cursor.insertRow([row]) &lt;SPAN class=""&gt;#have to insert a list not a single value&lt;/SPAN&gt;

&lt;SPAN class=""&gt;# Delete cursor object&lt;/SPAN&gt;
&lt;SPAN class=""&gt;del&lt;/SPAN&gt; cursor&lt;/PRE&gt;&lt;P&gt;When I run the code I just break the layer&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 22:22:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-search-and-insert-cursor-to-find-certain/m-p/1109489#M62722</guid>
      <dc:creator>WillemVan_Riet1</dc:creator>
      <dc:date>2021-10-20T22:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using Search and Insert Cursor to Find Certain Values and Replicate</title>
      <link>https://community.esri.com/t5/python-questions/using-search-and-insert-cursor-to-find-certain/m-p/1109551#M62725</link>
      <description>&lt;P&gt;Basic code would be something like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# read all attributes you want to copy, not just Subcat_3! Especially Shape, else you won't see the feature.
fields = ["SHAPE@", "Subcat_2", "Subcat_3"]

# use an SQL query ("Subcat_3 IS NOT NULL" or "Subcat_3 &amp;lt;&amp;gt; 'Nothing'")
values = [list(row) for row in arcpy.da.SearchCursor(social_layer, fields, "Subcat_3 IS NOT NULL")]

# I don't understand why you would want to have unique values?
# According to your question, you want to copy _every_ row with values in Subcat_3.

with arcpy.da.InsertCursor(social_layer, fields) as cursor:
    for row in values:
        # replace Subcat_2 with Subcat_3, delete Subcat_3
        row[-2] = row[-1]
        row[-1] = None
        # insert
        cursor.insertRow(row)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 21 Oct 2021 06:14:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-search-and-insert-cursor-to-find-certain/m-p/1109551#M62725</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-10-21T06:14:45Z</dc:date>
    </item>
  </channel>
</rss>

