4

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

6

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.

  • is this with VBA or python? because i don't know yet how python works... – niels Jan 6 '15 at 9:36
  • it's Python. Just put the names of your fields between ! ! – radouxju Jan 6 '15 at 9:44
  • In VBA it would be ([field1]+[field2]+[field3]+[field4])/4 – SIslam Jan 6 '15 at 18:18
  • if there is writtin <null> in a field -> is it count as a zero if you applied the formule? In case no, how it's possible to tell the tool <null> means zero '0'? – niels Jan 12 '15 at 19:05
0

Building on radouxju's answer, the right code for ArcGIS field calculator is pasted here for the convenience of copy-and-paste friend (radouxju'codes miss a few parenthesis).

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

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.