<?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: Update Cursor to Calculate Field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391581#M30942</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried your suggestion, but still no luck. However, looking at the ArcGIS 10.1 resource documentation, it should be as shown. I can't help but think it has something to do with the division of the rows... row[2] = row[1]/row[0].&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 07 Dec 2013 22:58:17 GMT</pubDate>
    <dc:creator>KevinWilliams</dc:creator>
    <dc:date>2013-12-07T22:58:17Z</dc:date>
    <item>
      <title>Update Cursor to Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391579#M30940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to use an update cursor to calculate a field. Basically, I'm trying to avoid division by 0 by looking in row[0] and see if it's 0. My code thus far is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
fc="C:/Temp/crimeGrid.shp"
fields="'MEAN_GRIDC', 'SUM_Join_C', 'crimeRate')
with arcpy.da.UpdateCursor(fc,fields) 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; if (row[0] &amp;gt; 0):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = row[1]/row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas or help on what I'm missing? I presume that it's the calculation aspect of my code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Dec 2013 16:09:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391579#M30940</guid>
      <dc:creator>KevinWilliams</dc:creator>
      <dc:date>2013-12-07T16:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor to Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391580#M30941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;SPAN&gt;You need to pass the fields variable in as a python list type (using [ ] ).&amp;nbsp; See more about python types [url=&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://docs.python.org/2/tutorial/datastructures.html]here[/url" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/2/tutorial/datastructures.html]here[/url&lt;/A&gt;&lt;SPAN&gt;].&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
fc = "C:/Temp/crimeGrid.shp"
fields = ['MEAN_GRIDC', 'SUM_Join_C', 'crimeRate']
with arcpy.da.UpdateCursor(fc,fields) 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; if row[0] &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = row[1]/row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This should do the trick.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:56:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391580#M30941</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T17:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor to Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391581#M30942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried your suggestion, but still no luck. However, looking at the ArcGIS 10.1 resource documentation, it should be as shown. I can't help but think it has something to do with the division of the rows... row[2] = row[1]/row[0].&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Dec 2013 22:58:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391581#M30942</guid>
      <dc:creator>KevinWilliams</dc:creator>
      <dc:date>2013-12-07T22:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor to Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391582#M30943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry for the ridiculous question. I continually thought it was in the division of rows, so I looked into my fields a little closer. Turns out, Row[0] and Row[1] were Double and Row[2] was Long. Fixed that aspect and the code works as is.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Dec 2013 23:07:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-to-calculate-field/m-p/391582#M30943</guid>
      <dc:creator>KevinWilliams</dc:creator>
      <dc:date>2013-12-07T23:07:41Z</dc:date>
    </item>
  </channel>
</rss>

