<?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: Use UpdateCursor to update field based on a change in another field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88790#M6893</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay so this probably isn't the best fix but solved by using arcpy.Sort_management(inFeatures, outFeatures, ["PASS_NUM", "ASCENDING"]) and then removing the sorted tag before initializing the update cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for the input!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Nov 2013 13:13:57 GMT</pubDate>
    <dc:creator>JensenConnor</dc:creator>
    <dc:date>2013-11-19T13:13:57Z</dc:date>
    <item>
      <title>Use UpdateCursor to update field based on a change in another field</title>
      <link>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88786#M6889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to update a field "TPN" based on another field "PASS_NUM". In my script "TPN" is a newly added number field and thus blank, "PASS_NUM" is also a number field but it contains the wrong numbers. I want to assign values to "TPN" when "PASS_NUM" is no longer equal the the value in the row above it. The feature class table is sorted by "PASS_NUM". See example of table I want to achieve attached: [ATTACH=CONFIG]29165[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The PASS_NUM field does not increment by 1 each time (i.e. it may skip 7) but the I want to TPN to only go up one. Is this possible using the UpdateCursor in arcpy? Or is there another way to achieve this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks much!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 13:38:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88786#M6889</guid>
      <dc:creator>JensenConnor</dc:creator>
      <dc:date>2013-11-18T13:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use UpdateCursor to update field based on a change in another field</title>
      <link>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88787#M6890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jensen,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This can be done in a model or very quickly manually.&lt;/SPAN&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Run your table with PASS_NUM through the Summary statistics tool and group by PASS_NUM&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Add a new field to this stats table called "X"&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;copy the FID\objectID into "X", this is your incremental number&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Join the stats table to your table based upon PASS_NUM&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;copy "X" into TPN&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 13:46:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88787#M6890</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2013-11-18T13:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use UpdateCursor to update field based on a change in another field</title>
      <link>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88788#M6891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is an example using an update cursor. Untested.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

table = 'some_table'
last_val = None
count = 0
cursor = sorted(arcpy.da.UpdateCursor(table, ['PASS_NUM', 'TPN']))
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] == last_val:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = count
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif row[0] != last_val:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = count
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_val = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:23:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88788#M6891</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-10T23:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Use UpdateCursor to update field based on a change in another field</title>
      <link>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88789#M6892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Matthew,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your input. I think this code is very close to working for me. I got a chance to test it out and it throws an AttributeError: 'list' object has no attribute 'updateRow'. The line in question being cursor.updateRow(row). I will continue to play around with this and let you know if I figure anything out. Let me know if you have any ways around this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Nov 2013 12:57:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88789#M6892</guid>
      <dc:creator>JensenConnor</dc:creator>
      <dc:date>2013-11-19T12:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Use UpdateCursor to update field based on a change in another field</title>
      <link>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88790#M6893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay so this probably isn't the best fix but solved by using arcpy.Sort_management(inFeatures, outFeatures, ["PASS_NUM", "ASCENDING"]) and then removing the sorted tag before initializing the update cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for the input!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Nov 2013 13:13:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-updatecursor-to-update-field-based-on-a-change/m-p/88790#M6893</guid>
      <dc:creator>JensenConnor</dc:creator>
      <dc:date>2013-11-19T13:13:57Z</dc:date>
    </item>
  </channel>
</rss>

