[GIS] Calculate average value for each row

arcgis-desktoparcmapfield-calculator

The picture is an example, but the method would be the same at mine bigger dataset.
So i have some parcels with each a ID value and some fields.
such as field 1, field 2, field 3, fieldd 4,… with some numbers in the columns.

Now the objective is to calculate the average for each parcel (ID), so for each row and locate the answer in a new field 'average'.

how is it possible? i only know the way to calculate a average for a column, not for a row…

field average

Best Answer

you can use the field calculator with the Python parser

sum([!field1!, !field2!, !field3!, !field4!])/4

EDIT: for accounting for null values

sum([a for a in [!field1!, !field2!, !field3!, !field4!] if a is not None )/4

not that, in this case, it works as if you assume that null values are ZERO as in your comment. Alternatively, you can IGNORE null values in the mean (so you divide with the number of valid field values.

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] )

Here I used a little trick to avoid errors when all fields are Null (will return 0). This is a weak error handling, but in one line.

Related Question