AnsweredAssumed Answered

calculate function in python jupyter notebook

Question asked by drycreekeng on Apr 9, 2020
Latest reply on Apr 10, 2020 by drycreekeng

Hi everyone,

I am trying to create a script to run every night to calculate the total insects counted each day by summing two insect  count fields in a feature layer.  I can't use Arcade because the layer has "track changes" and "sync" enabled for the field crew (grrrr...). Below is my simple script to calculate the "TotalArmyworms" field based on summing the Western Yellow Armyworm field with the Bertha Armyworm field. I have tried many different ways to identify the layer from AGOL, and each time the error states that 'Item' object has no attribute 'calculate'.  Any thoughts?


import arcgis
import arcpy
from arcgis.gis import GIS
from arcgis import features
from arcgis.features import FeatureLayer

gis = GIS('', 'xxxxxx', 'xxxxxx')
arcpy.env.overwriteOutput = True

trap_count = gis.content.get("b6b9c68fa42b408a88c68aa9e18593d5")

trap_count.calculate(where="fid > 0", calc_expression=[{"field": "TotalArmyworms", "sqlExpression" : "Nu_W_YellowStripedArmyworm + Nu_BerthArmyworm" }])

KeyError                                  Traceback (most recent call last)
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\ in __getattr__(self, name)
   6998         try:
-> 6999             return dict.__getitem__(self, name)
   7000         except:

KeyError: 'calculate'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-50-2608a815f7ee> in <module>
----> 1 trap_count.calculate(where="fid > 0", calc_expression=[{"field": "TotalArmyworms", "sqlExpression" : "Nu_W_YellowStripedArmyworm + Nu_BerthArmyworm" }])

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\ in __getattr__(self, name)
   6999             return dict.__getitem__(self, name)
   7000         except:
-> 7001             raise AttributeError("'%s' object has no attribute '%s'" % (type(self).__name__, name))
   7003     def __getitem__(self, k): # support item attributes as dictionary keys on this object

AttributeError: 'Item' object has no attribute 'calculate'