I have a feature class with 20 fields and 13 of them have datas from year 2003 to 2015. I create a new field named 'mean' which will calculate the mean value only for the values from 2003 to 2015. All this fields has a equal sufix named 'ACH'. Here is the problem: I tried many ways to do the mean in the new field, using wildcard, but the script complete with no errors but do not calculate.
It`s not the mean from the column itself. I need to sum all the columns and divide in the new 'mean' fild, with this I will get the mean value for each cell.
What`s the best way to do?
I found some ways, but no one using wildcards.
import arcpy, math featureclass = arcpy.GetParameterAsText(0) field_names = [f.name for f in arcpy.ListFields(featureclass, '*ACH*')] if field_names == '*ACH*': x = sum([a for a in [0, !field1!, !field2!, !field3!, !field4!] if a is not None] ) / max([1,len([a for a in [ !field1!, !field2!, !field3!, !field4!] if a is not None] )]) arcpy.AddField_management(featureclass, 'mean', 'float') arcpy.CalculateField_management(featureclass, 'mean', '!x!' , "PYTHON_9.3", "")
Here is the table. There is many others fields in the table, but I want to calculate only the mean from the fields ACH_M1S_20XX (XX representes the year) tha preffix is ACH. I only want to calculate the values from all years, and put in a new field called mean.
field1 + field2 + .... + fieldX / field quantities = mean. there is a value for each cell in the line. remember, it`s not the column mean, is the line mean.