I have an ESRI featureclass with a lot of records that have been scored to certain criteria, although criteria have been left null for records where they aren't deemed relevant.

I'm now trying to produce the final scores for each record, which require adding all the values for each feature and dividing by the number of criteria scored. Is there any easy way to script this?

I am trying to think of a way to run through each feature and calculate the number of criteria scored... or conversely, the number of criteria left null.

I am attempting the following code in the field calculator but not having any luck so far, am I on the right lines?

def mean(Welcoming, Access, Community, Safe, Provision, Quality, Security, Dog, Litter, Grounds): 
   fieldList = [Welcoming, Access, Community, Safe, Provision, Quality, Security, Dog, Litter, Grounds] 
   validList = [] 
   for i in fieldList: 
      if i != None: 
   meanVal = sum(validList)/len(validList) 
   return meanVal
  • 1
    I would use arcpy.da.UpdateCursor(). – PolyGeo Jul 7 '17 at 10:56
  • Thanks, I am still very new to for loops... can you give me a pointer to get started with this please? – Luke Jul 7 '17 at 11:04
  • The help for that function has some useful sample code. Otherwise there are lots of code snippets using it on this site. – PolyGeo Jul 7 '17 at 11:46
  • 1
    For counting of NULLs, arcpy.da.SearchCursor is the right tool. – Vince Jul 7 '17 at 12:57

Your code has an indentation error where:

  if i != None: 

should be:

  if i != None: 

but otherwise it looks like it is on the right track.

Without more details like any errors that result when you run that code in the ArcGIS Field Calculator I do not think I can provide more help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.