<?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: Convert Excel formula to Python 2022 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/convert-excel-formula-to-python-2022/m-p/1136335#M63570</link>
    <description>&lt;P&gt;You need to use a cursor.&amp;nbsp; Something like this, but keep in mind that it only works if your object_id's are grouped like in your image. they are not, you can use an order by sql clause in the cursor to group them in the desired order.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;previous_object_id = None
previous_vertex_val = 1

with arcpy.da.UpdateCursor(fc, ["object_id", "Vertex"]) as cursor:
    for row in cursor:
        # check if the current object_id is the same as the previous.
        if str(row[0]) == str(previous_object_id):
            # set vertex to current vertex value
            row[1] = previous_vertex_val
            # increase the vertex previous value by 1
            previous_vertex_val += 1
        else: # new object_id, reset the object_id and previous_vertex val
            # reset the object_id and vertex value to 1
            previous_object_id = str(row[0])
            previous_vertex_val = 1
            # set vertex in the fc to 1
            row[1] = previous_vertex_val

        # update the row
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jan 2022 13:00:32 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2022-01-24T13:00:32Z</dc:date>
    <item>
      <title>Convert Excel formula to Python 2022</title>
      <link>https://community.esri.com/t5/python-questions/convert-excel-formula-to-python-2022/m-p/1136310#M63569</link>
      <description>&lt;P&gt;Hello everybody, i would like to be helped form you for a excel formula , that i need some help to convert to python code for GIS attributes.&lt;BR /&gt;&lt;BR /&gt;I have this excel formula """=IF(A2&amp;lt;&amp;gt;A1,1,B1+1)"""" that give valued number from 1,2,3,4, etc to Vertec column when the other row value change.&lt;BR /&gt;&lt;BR /&gt;For example when the object_ID change form 5/75 to another value the numer starts counting form the 1,2,3,4,5 etc until another Object_id changes again.&lt;BR /&gt;&lt;BR /&gt;Photo attach.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sami04_1-1643017687586.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/32082iAD1BA159017AF396/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sami04_1-1643017687586.png" alt="Sami04_1-1643017687586.png" /&gt;&lt;/span&gt;&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;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 10:08:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-excel-formula-to-python-2022/m-p/1136310#M63569</guid>
      <dc:creator>Sami04</dc:creator>
      <dc:date>2022-01-24T10:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Excel formula to Python 2022</title>
      <link>https://community.esri.com/t5/python-questions/convert-excel-formula-to-python-2022/m-p/1136335#M63570</link>
      <description>&lt;P&gt;You need to use a cursor.&amp;nbsp; Something like this, but keep in mind that it only works if your object_id's are grouped like in your image. they are not, you can use an order by sql clause in the cursor to group them in the desired order.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;previous_object_id = None
previous_vertex_val = 1

with arcpy.da.UpdateCursor(fc, ["object_id", "Vertex"]) as cursor:
    for row in cursor:
        # check if the current object_id is the same as the previous.
        if str(row[0]) == str(previous_object_id):
            # set vertex to current vertex value
            row[1] = previous_vertex_val
            # increase the vertex previous value by 1
            previous_vertex_val += 1
        else: # new object_id, reset the object_id and previous_vertex val
            # reset the object_id and vertex value to 1
            previous_object_id = str(row[0])
            previous_vertex_val = 1
            # set vertex in the fc to 1
            row[1] = previous_vertex_val

        # update the row
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 13:00:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-excel-formula-to-python-2022/m-p/1136335#M63570</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-24T13:00:32Z</dc:date>
    </item>
  </channel>
</rss>

