<?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: Field Caluclator Error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394335#M31195</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I figured this issue out. i need to add the + sign into the variable so that the script looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;GrpField1= "Nest_All.GrpSz08" #User selects field GrpField2= "Nest_All.GrpSz09" #User selects field GrpField3= "Nest_All.GrpSz10" #User selects field GrpField4= "Nest_All.GrpSz11" #User Selects field GrpField5= "Nest_All.GrpSz12" #User selects field GrpField1New= '!'+GrpField1+'!+' GrpField2New= '!'+GrpField2+'!+' GrpField3New= '!'+GrpField3+'!+' GrpField4New= '!'+GrpField4+'!+' GrpField5New= '!'+GrpField5+'!'&amp;nbsp; GrpExpression = (GrpField1New+GrpField2New+GrpField3New+GrpField4New+GrpField5New)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I'm also having a similar issue with this calculation&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#Get count of how many records are selected. This calculation is used to calculate avg group size and avg pbg size over the past five yrs. &amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedCount=int(arcpy.GetCount_management(CbuffersFL).getOutput(0)) &amp;nbsp;&amp;nbsp;&amp;nbsp; print "\nThere are",SelectedCount, "buffers that intersect with parcel", FID&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #calculate the avg group size for selected groups. This avgerage will be temporarily recorded into the GrpAvg0812 Field located within CbuffersFL. &amp;nbsp;&amp;nbsp;&amp;nbsp; #Once calculated an update cursor will be used to record this average in the selected parcels shapefile. &amp;nbsp;&amp;nbsp;&amp;nbsp; GrpFieldJoin=CbuffersFL[:-6]+"."+TotalGrpField &amp;nbsp;&amp;nbsp;&amp;nbsp; GrpFieldJoinNew='!'+GrpFieldJoin+'!/' &amp;nbsp;&amp;nbsp;&amp;nbsp; GrpExpression=(GrpFieldJoinNew)/SelectedCount)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know the issue is that GrpFieldJoinNew is a string but if I code the expression to read&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;GrpExpression=(int(GrpFieldJoinNew)/SelectCount)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this message&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;ValueError: invalid literal for int() with base 10: '!RCW_Cluster_2010_3miBuff.TotGrpCalc!/'&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure how I turn this string into an interger value&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Mar 2013 19:29:20 GMT</pubDate>
    <dc:creator>RachelAlbritton1</dc:creator>
    <dc:date>2013-03-27T19:29:20Z</dc:date>
    <item>
      <title>Field Caluclator Error</title>
      <link>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394332#M31192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've written a script. that uses the field calculator to create a value for a new field, "TotGroupField". This field value is = to Field1+Field2+Field3....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm getting the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Traceback (most recent call last): &amp;nbsp; File RCW\Code\ForLoop.py", line 99, in &amp;lt;module&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; GrpExpression = sum([GrpField1New+GrpField2New+GrpField3New+GrpField4New+GrpField5New]) TypeError: unsupported operand type(s) for +: 'int' and 'str'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#Create Feature Layers from Feature Classes parcelsFC = "ACUB_3mile.shp" parcelsFL = outName(parcelsFC,"_Layer") CbuffersFL = outName(CBuffersFC,"_Layer")&amp;nbsp; arcpy.MakeFeatureLayer_management(parcelsFC, parcelsFL) arcpy.MakeFeatureLayer_management(CBuffersFC, CbuffersFL)&amp;nbsp; TotalGrpField = "TotGrpCalc" #Temp - will be deleted TotalPBGField = "TotaBGCalc" #Temp - Will be deleted AvgGrpField= "AvgGrp0812" #Make into user input AvgPBGField= "AvgPBG0812" #Make into user input arcpy.AddField_management(CbuffersFL,TotalGrpField,"DOUBLE") print arcpy.GetMessages(),"\n" arcpy.AddField_management(CbuffersFL,TotalPBGField,"DOUBLE") print arcpy.GetMessages(),"\n" arcpy.AddField_management(CbuffersFL,AvgGrpField, "DOUBLE") print arcpy.GetMessages(),"\n" arcpy.AddField_management(CbuffersFL,AvgPBGField,"DOUBLE") print arcpy.GetMessages(),"\n"&amp;nbsp; #Join All Nest Files Table to new selected buffer file. This table was preproccessed and made into a single dbf table (joined by cluster key) showing groupsize and PBG by year. #A column was created called TotalSize and Total PGB for each cluster. The total column will be used to help calculate the average group size/average pbg size for RCW clusters #whose 3-mile dispersal buffer intersect with each parcel.&amp;nbsp; #This means this table will have to be updated manually every year unless written into the script. #This join is used to calculate criteria 2 and 3. #Input for a join must be a layer&amp;nbsp; NestFiles="/RCW/Nest Data/Edited Nest Data/Nest_All.dbf" arcpy.AddJoin_management(CbuffersFL,"Cluster_ke",NestFiles,"Key12","KEEP_ALL") print arcpy.GetMessages(),"\n"&amp;nbsp;&amp;nbsp; GrpField1= "Nest_All.GrpSz08" #User selects field GrpField2= "Nest_All.GrpSz09" #User selects field GrpField3= "Nest_All.GrpSz10" #User selects field GrpField4= "Nest_All.GrpSz11" #User Selects field GrpField5= "Nest_All.GrpSz12" #User selects field GrpField1New= "!"+GrpField1+"!" GrpField2New= "!"+GrpField2+"!" GrpField3New= "!"+GrpField3+"!" GrpField4New= "!"+GrpField4+"!" GrpField5New= "!"+GrpField5+"!"&amp;nbsp; GrpExpression = sum([GrpField1New+GrpField2New+GrpField3New+GrpField4New+GrpField5New])&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(CbuffersFL,TotalGrpField,GrpExpression,"PYTHON") print arcpy.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 18:22:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394332#M31192</guid>
      <dc:creator>RachelAlbritton1</dc:creator>
      <dc:date>2013-03-27T18:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Field Caluclator Error</title>
      <link>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394333#M31193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;One of these fields is type Text or non-numeric&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;sum([GrpField1New+GrpField2New+GrpField3New+GrpField4New+GrpField5New])&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 18:50:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394333#M31193</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-03-27T18:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: Field Caluclator Error</title>
      <link>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394334#M31194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, so based &lt;/SPAN&gt;&lt;A href="http://gis.stackexchange.com/questions/28176/arcmap-10-0-python-field-calculator-find-replace-double-quotes/28195#28195" rel="nofollow noopener noreferrer" target="_blank"&gt;on this article&lt;/A&gt;&lt;SPAN&gt;, I replaced the double quotes with single quotes. The output message of the tool now says that its running successfully, but when I use a search cursor to get the values of the rows, the values are incorrect. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is leading me to believe that even though the arcpy module is saying the tool is successfully calculating these fields, there is still an issue with formatting.&amp;nbsp; Thoughts?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;New Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
TotalGrpField = "TotGrpCalc" #Temp - will be deleted
TotalPBGField = "TotaBGCalc" #Temp - Will be deleted
AvgGrpField= "AvgGrp0812" #Make into user input
AvgPBGField= "AvgPBG0812" #Make into user input
arcpy.AddField_management(CbuffersFL,TotalGrpField,"DOUBLE")
print arcpy.GetMessages(),"\n"
arcpy.AddField_management(CbuffersFL,TotalPBGField,"DOUBLE")
print arcpy.GetMessages(),"\n"
arcpy.AddField_management(CbuffersFL,AvgGrpField, "DOUBLE")
print arcpy.GetMessages(),"\n"
arcpy.AddField_management(CbuffersFL,AvgPBGField,"DOUBLE")
print arcpy.GetMessages(),"\n"

#Join All Nest Files Table to new selected buffer file. This table was preproccessed and made into a single dbf table (joined by cluster key) showing groupsize and PBG by year.
#A column was created called TotalSize and Total PGB for each cluster. The total column will be used to help calculate the average group size/average pbg size for RCW clusters
#whose 3-mile dispersal buffer intersect with each parcel. 
#This means this table will have to be updated manually every year unless written into the script.
#This join is used to calculate criteria 2 and 3.

#Input for a join MUST BE A LAYER

NestFiles="/RCW/Nest Data/Edited Nest Data/Nest_All.dbf"
arcpy.AddJoin_management(CbuffersFL,"Cluster_ke",NestFiles,"Key12","KEEP_ALL")
print arcpy.GetMessages(),"\n"


GrpField1= "Nest_All.GrpSz08" #User selects field
GrpField2= "Nest_All.GrpSz09" #User selects field
GrpField3= "Nest_All.GrpSz10" #User selects field
GrpField4= "Nest_All.GrpSz11" #User Selects field
GrpField5= "Nest_All.GrpSz12" #User selects field
GrpField1New= '!'+GrpField1+'!'
GrpField2New= '!'+GrpField2+'!'
GrpField3New= '!'+GrpField3+'!'
GrpField4New= '!'+GrpField4+'!'
GrpField5New= '!'+GrpField5+'!'

GrpExpression = (GrpField1New+GrpField2New+GrpField3New+GrpField4New+GrpField5New)

arcpy.CalculateField_management(CbuffersFL,TotalGrpField,GrpExpression,"PYTHON")
print arcpy.GetMessages()


#Check to see if calculation is working
TotalGrpFieldNew=CbuffersFL[:-6]+"."+TotalGrpField
print TotalGrpFieldNew
sc = arcpy.SearchCursor(CbuffersFL)
for line in sc:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print line.getValue(TotalGrpFieldNew)
del line
del sc
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:04:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394334#M31194</guid>
      <dc:creator>RachelAlbritton1</dc:creator>
      <dc:date>2021-12-11T18:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Field Caluclator Error</title>
      <link>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394335#M31195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I figured this issue out. i need to add the + sign into the variable so that the script looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;GrpField1= "Nest_All.GrpSz08" #User selects field GrpField2= "Nest_All.GrpSz09" #User selects field GrpField3= "Nest_All.GrpSz10" #User selects field GrpField4= "Nest_All.GrpSz11" #User Selects field GrpField5= "Nest_All.GrpSz12" #User selects field GrpField1New= '!'+GrpField1+'!+' GrpField2New= '!'+GrpField2+'!+' GrpField3New= '!'+GrpField3+'!+' GrpField4New= '!'+GrpField4+'!+' GrpField5New= '!'+GrpField5+'!'&amp;nbsp; GrpExpression = (GrpField1New+GrpField2New+GrpField3New+GrpField4New+GrpField5New)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I'm also having a similar issue with this calculation&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#Get count of how many records are selected. This calculation is used to calculate avg group size and avg pbg size over the past five yrs. &amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedCount=int(arcpy.GetCount_management(CbuffersFL).getOutput(0)) &amp;nbsp;&amp;nbsp;&amp;nbsp; print "\nThere are",SelectedCount, "buffers that intersect with parcel", FID&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #calculate the avg group size for selected groups. This avgerage will be temporarily recorded into the GrpAvg0812 Field located within CbuffersFL. &amp;nbsp;&amp;nbsp;&amp;nbsp; #Once calculated an update cursor will be used to record this average in the selected parcels shapefile. &amp;nbsp;&amp;nbsp;&amp;nbsp; GrpFieldJoin=CbuffersFL[:-6]+"."+TotalGrpField &amp;nbsp;&amp;nbsp;&amp;nbsp; GrpFieldJoinNew='!'+GrpFieldJoin+'!/' &amp;nbsp;&amp;nbsp;&amp;nbsp; GrpExpression=(GrpFieldJoinNew)/SelectedCount)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know the issue is that GrpFieldJoinNew is a string but if I code the expression to read&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;GrpExpression=(int(GrpFieldJoinNew)/SelectCount)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this message&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;ValueError: invalid literal for int() with base 10: '!RCW_Cluster_2010_3miBuff.TotGrpCalc!/'&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure how I turn this string into an interger value&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 19:29:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394335#M31195</guid>
      <dc:creator>RachelAlbritton1</dc:creator>
      <dc:date>2013-03-27T19:29:20Z</dc:date>
    </item>
    <item>
      <title>Divide field values by an integer</title>
      <link>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394336#M31196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to divide field values by an integer using field calculator. The integer value is being derived from a arcpy.GetCount statement and the fielded is in a joined table wherein the field itself is part of the origin table (I know you can't use field calculator on the joined table).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for parcel in range(0,1092):
&amp;nbsp;&amp;nbsp;&amp;nbsp; FID = "FID=%s" % (parcel)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(SelectedParcelsFL,"NEW_SELECTION",FID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(CbuffersFL,"INTERSECT",SelectedParcelsFL)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Get count of how many records are selected. This calculation is used to calculate avg group size and avg pbg size over the past five yrs.
&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedCount=int(arcpy.GetCount_management(CbuffersFL).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\nThere are",SelectedCount, "buffers that intersect with parcel", FID

&amp;nbsp;&amp;nbsp;&amp;nbsp; #calculate the avg group size for selected groups. This avgerage will be temporarily recorded into the GrpAvg0812 Field located within CbuffersFL.
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Once calculated an update cursor will be used to record this average in the selected parcels shapefile.
&amp;nbsp;&amp;nbsp;&amp;nbsp; GrpFieldJoin=CbuffersFL[:-6]+"."+TotalGrpField
&amp;nbsp;&amp;nbsp;&amp;nbsp; GrpFieldJoinNew='!'+GrpFieldJoin+'!'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Calculating average group size over the last 5 years for RCW Clusters whose 3-mile dispersal buffer intercects each parcel")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(CbuffersFL,AvgGrpField,(GrpFieldJoinNew/SelectedCount),"PYTHON")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following error&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
TypeError: unsupported operand type(s) for /: 'str' and 'int'
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm understanding this to mean that the GrpJoinFieldNew is a string, but if I try to structure it as an integer&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
(int(GrpFieldJoinNew)/SelectedCount)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
ValueError: invalid literal for int() with base 10: '!RCW_Cluster_2010_3miBuff.TotGrpCalc!'
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:04:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394336#M31196</guid>
      <dc:creator>RachelAlbritton1</dc:creator>
      <dc:date>2021-12-11T18:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Divide field values by an integer</title>
      <link>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394337#M31197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;the field you are trying is a text/string field and it is probably left justified or it contains null values, float the field value then do the division&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 21:13:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394337#M31197</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-03-27T21:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Divide field values by an integer</title>
      <link>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394338#M31198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;BR /&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(CbuffersFL,AvgGrpField,(GrpFieldJoinNew/SelectedCount),"PYTHON")
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above calculate expression is not properly formed. The divide symbol must be inside the expression string. (This is the same solution you posted earlier today -- in fact I merged the threads here.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's a way to approach building the expression using Python string formatting -- generally far easier to debug than adding strings together the way you've been doing it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
SelectedCount=int(arcpy.GetCount_management(CbuffersFL).getOutput(0))
&lt;SPAN style="color:&amp;quot;#008000&amp;quot;;"&gt;# the name is used to prefix the field name
&lt;/SPAN&gt;prefix = arcpy.Describe(CbuffersFL).name 
expr = &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"!{0}.{1}! / float({2})"&lt;/SPAN&gt;.format(prefix, TotalGrpField, SelectedCount)
arcpy.CalculateField_management(CbuffersFL, AvgGrpField, expr, &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"PYTHON_9.3"&lt;/SPAN&gt;)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's how using the python formatting simplifies your field addition calculation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
GrpField1= &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"Nest_All.GrpSz08" &lt;/SPAN&gt;
GrpField2= &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"Nest_All.GrpSz09"&lt;/SPAN&gt;
GrpField3= &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"Nest_All.GrpSz10&lt;/SPAN&gt;" 
GrpField4= &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"Nest_All.GrpSz11"&lt;/SPAN&gt; 
GrpField5= &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"Nest_All.GrpSz12" &lt;/SPAN&gt;
fmt = &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"!{0}! + !{1}! + !{2}! + !{3}! + !{4}! + !{5}!" &lt;/SPAN&gt;
Grpexpression = fmt.format(GrpField1New, GrpField2New, \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GrpField3New, GrpField4New, GrpField5New)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Python also has a sum function for lists, so you could have done this too:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fmt = &lt;SPAN style="color:&amp;quot;#B22222&amp;quot;;"&gt;"sum([!{0}!, !{1}!, !{2}!, !{3}!, !{4}!, !{5}!])" &lt;/SPAN&gt;
Grpexpression = fmt.format(GrpField1New, GrpField2New, \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GrpField3New, GrpField4New, GrpField5New)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps you out.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:04:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-caluclator-error/m-p/394338#M31198</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T18:04:10Z</dc:date>
    </item>
  </channel>
</rss>

