<?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 Sum rows of a field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88626#M6876</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;SPAN&gt;I'm trying to create a single scalar value as the sum of a row, then use the scalar in a field calculation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want the sum of "UTC10_FT" call it tot_utc_ft, then use that value in a calculate field:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to find the sum value:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;list2 = []
rows = arcpy.SearchCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; utc_ft = row.getValue("UTC10_Ft")
&amp;nbsp;&amp;nbsp;&amp;nbsp; list2.append(utc_ft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; tot_utc_ft = sum(list2)

arcpy.CalculateField_management(parcels, "Tot_UTC_Pct", """!UTC10_Ft! / tot_utc_ft""", "PYTHON")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Currently getting this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tot_utc_ft = sum(list)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sure this is something simple, but admittedly, not a great python programmer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The next question will be whether python will use my tot_utc_ft variable within field calculator? Or, do I need to perform this operation within an expression?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 Nov 2011 15:51:10 GMT</pubDate>
    <dc:creator>RichardThurau</dc:creator>
    <dc:date>2011-11-23T15:51:10Z</dc:date>
    <item>
      <title>Sum rows of a field</title>
      <link>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88626#M6876</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;SPAN&gt;I'm trying to create a single scalar value as the sum of a row, then use the scalar in a field calculation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want the sum of "UTC10_FT" call it tot_utc_ft, then use that value in a calculate field:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to find the sum value:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;list2 = []
rows = arcpy.SearchCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; utc_ft = row.getValue("UTC10_Ft")
&amp;nbsp;&amp;nbsp;&amp;nbsp; list2.append(utc_ft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; tot_utc_ft = sum(list2)

arcpy.CalculateField_management(parcels, "Tot_UTC_Pct", """!UTC10_Ft! / tot_utc_ft""", "PYTHON")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Currently getting this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tot_utc_ft = sum(list)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sure this is something simple, but admittedly, not a great python programmer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The next question will be whether python will use my tot_utc_ft variable within field calculator? Or, do I need to perform this operation within an expression?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Nov 2011 15:51:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88626#M6876</guid>
      <dc:creator>RichardThurau</dc:creator>
      <dc:date>2011-11-23T15:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sum rows of a field</title>
      <link>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88627#M6877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Rich,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe you are receiving that error because you have a NULL, or empty, value for one of the rows.&amp;nbsp; Perform a search by attribute and then convert all NULL values to 0 and try your script again.&amp;nbsp; Also, you will be able to use the variable in the field calculator.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Nov 2011 16:17:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88627#M6877</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2011-11-23T16:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Sum rows of a field</title>
      <link>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88628#M6878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi,&lt;BR /&gt;I'm trying to create a single scalar value as the sum of a row, then use the scalar in a field calculation:&lt;BR /&gt;&lt;BR /&gt;I want the sum of "UTC10_FT" call it tot_utc_ft, then use that value in a calculate field:&lt;BR /&gt;&lt;BR /&gt;to find the sum value:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;list2 = []
rows = arcpy.SearchCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; utc_ft = row.getValue("UTC10_Ft")
&amp;nbsp;&amp;nbsp;&amp;nbsp; list2.append(utc_ft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; tot_utc_ft = sum(list2)

arcpy.CalculateField_management(parcels, "Tot_UTC_Pct", """!UTC10_Ft! / tot_utc_ft""", "PYTHON")
&lt;/PRE&gt;&lt;BR /&gt;Currently getting this error:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tot_utc_ft = sum(list)&lt;BR /&gt;TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'&lt;BR /&gt;&lt;BR /&gt;I'm sure this is something simple, but admittedly, not a great python programmer.&lt;BR /&gt;&lt;BR /&gt;The next question will be whether python will use my tot_utc_ft variable within field calculator? Or, do I need to perform this operation within an expression?&lt;BR /&gt;&lt;BR /&gt;Thanks for your help.&lt;BR /&gt;&lt;BR /&gt;rich&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Looks like some of your row.UTC10_Ft has null value in it. -never mind. Jake says it&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:23:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88628#M6878</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2021-12-10T23:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sum rows of a field</title>
      <link>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88629#M6879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Many Thanks!! Pesky nulls.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Nov 2011 18:43:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-rows-of-a-field/m-p/88629#M6879</guid>
      <dc:creator>RichardThurau</dc:creator>
      <dc:date>2011-11-23T18:43:35Z</dc:date>
    </item>
  </channel>
</rss>

