<?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 Field calculator, sum of field. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141866#M11032</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having a bit of a problem with what seems like should be a simple field calculator expression. I have a table with about 50 rows and a column with acres for each row. I've created a new column called Percent_Acres (Double) and im looking to calculate the percent each feature makes up of the total acres. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want an expression equal to this Percent_Acres = Acres / Total Acres.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Normally this would be easy to do and i would just look up the field statistics for the sum. However this calculation is part of a model that will be automated so i need an expression that will automatically calculate the columns sum while in the field calculator. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears that i am having a problem with iterating through each row to add up to the total. I have tried numerous expressions and each time i get the same result telling me that "typeerror float object is not iterable"&lt;BR /&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any advise on this topic would be greatly appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, Ben&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Jan 2015 18:22:31 GMT</pubDate>
    <dc:creator>BenjaminMittler</dc:creator>
    <dc:date>2015-01-07T18:22:31Z</dc:date>
    <item>
      <title>Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141866#M11032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having a bit of a problem with what seems like should be a simple field calculator expression. I have a table with about 50 rows and a column with acres for each row. I've created a new column called Percent_Acres (Double) and im looking to calculate the percent each feature makes up of the total acres. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want an expression equal to this Percent_Acres = Acres / Total Acres.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Normally this would be easy to do and i would just look up the field statistics for the sum. However this calculation is part of a model that will be automated so i need an expression that will automatically calculate the columns sum while in the field calculator. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears that i am having a problem with iterating through each row to add up to the total. I have tried numerous expressions and each time i get the same result telling me that "typeerror float object is not iterable"&lt;BR /&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any advise on this topic would be greatly appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, Ben&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 18:22:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141866#M11032</guid>
      <dc:creator>BenjaminMittler</dc:creator>
      <dc:date>2015-01-07T18:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141867#M11033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Benjamin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a way you can do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def update(acres):
&amp;nbsp; import arcpy
&amp;nbsp; list = []
&amp;nbsp; with arcpy.da.SearchCursor(r"C:\temp\python\test.gdb\Sample", ["Acres"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row[0])
&amp;nbsp; S = sum(list)
&amp;nbsp; return acres / S * 100&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="screen1.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/48275_screen1.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:48:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141867#M11033</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T07:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141868#M11034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jake&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2015 19:45:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141868#M11034</guid>
      <dc:creator>BenjaminMittler</dc:creator>
      <dc:date>2015-01-12T19:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141869#M11035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I don't have "C:\temp\python\test.gdb\Sample" should I re-install Python?&lt;/P&gt;&lt;P&gt;&lt;IMG alt="2015-02-12 11_59_09-land_management_all - ArcMap.png" class="jive-image image-1" src="/legacyfs/online/61360_2015-02-12 11_59_09-land_management_all - ArcMap.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 21:00:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141869#M11035</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2015-02-12T21:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141870#M11036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is not the value you should use, it is only a sample value in the correct format for you to imitate.&amp;nbsp; You need to change the directory and feature class name to be the one you are actually calculating.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would also change the code to make the list a global variable so that you do not run the cursor for each record (it only needs to be done once).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;list = []
def update(acres):&amp;nbsp; 
&amp;nbsp; import arcpy&amp;nbsp; 
&amp;nbsp; global list&amp;nbsp; 
&amp;nbsp; if len(list) == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(r"C:\yourPath\yourGDB.gdb\yourFC", ["Acres"]) as cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row[0]) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor, row 
&amp;nbsp; S = sum(list)&amp;nbsp; 
&amp;nbsp; return acres / S * 100 &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:48:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141870#M11036</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T07:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141871#M11037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Cool trick about using the global list. I didn't know you could do that in a field calc!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 23:42:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141871#M11037</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-12T23:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141872#M11038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As the number of records being calculated grows, that trick quickly turns into a performance necessity. The same technique works for building a label expression function.&amp;nbsp; See &lt;A _jive_internal="true" href="https://community.esri.com/blogs/richard_fairhurst/2015/02/07/creating-labels-with-related-table-data"&gt;this blog on that subject&lt;/A&gt;.&amp;nbsp; I wrote the blog the same day the light dawned on me that a global variable was essential to using a cursor inside of a loop in order to avoid doing time consuming query repetitions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can run a cursor against your entire feature class or related FC/table and load value lists or summaries into dictionaries/lists for the entire record set, and then build labels using the in memory data not contained in the current record, without the performance hit of building SQL statements and running the cursor on every record.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 23:59:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141872#M11038</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-02-12T23:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141873#M11039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are stuck for time, export the table to excel and do it in excel. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Feb 2015 07:42:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141873#M11039</guid>
      <dc:creator>DXXX</dc:creator>
      <dc:date>2015-02-13T07:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141874#M11040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;LOL, yep&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Nov 2018 03:40:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/141874#M11040</guid>
      <dc:creator>warrenroberts</dc:creator>
      <dc:date>2018-11-06T03:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/1222817#M65874</link>
      <description>&lt;P&gt;This is absurd ... is this really the easiest way to sum a field in the field calculator?&amp;nbsp; Why doesn't something like this work:&lt;/P&gt;&lt;P&gt;!Shape_Area!/!Shape_Area!.sum()&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 14:45:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/1222817#M65874</guid>
      <dc:creator>JuneSkeeter</dc:creator>
      <dc:date>2022-10-18T14:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator, sum of field.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/1325804#M68539</link>
      <description>&lt;P&gt;Thanks for this revised script, it's worked perfectly.&lt;BR /&gt;&lt;BR /&gt;Since I'm making a tool to carry this out in ArcGISs ModelBuilder I was able to use inline variable substitution to replace r"C:\yourPath\yourGDB.gdb\yourFC" with "%Input Table%"&lt;/P&gt;&lt;P&gt;Right-click on the 'Calculate Field' tool within ModelBuilder, then Create Variable &amp;gt; From Parameter &amp;gt; Inpute Table. Right-click the Inpute Table and set it as a Parameter to allow user input for the tool.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 11:18:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-sum-of-field/m-p/1325804#M68539</guid>
      <dc:creator>FrankyAdair</dc:creator>
      <dc:date>2023-09-06T11:18:45Z</dc:date>
    </item>
  </channel>
</rss>

