Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Field calculator calculate mean values of multiple rows when some values are Nulls

$
0
0
Hello!

I need to calculate average value of 7 fields (Index2006, Index2007, Index2008, Index2009, Index2010, Index2011, Index2012) to field IlvesAve (see illustration).
Attachment 29714
The problem is that I have Null values in many rows. 0 values are real counting data, while Null values indicate the missing data. Null values can't be taken into account otherwise the results are incorrect. I can calculate sum value of indexes:

Code:

def stack(item1,item2,item3,item4,item5,item6,item7):
itemList = [item1,item2,item3,item4,item5,item6,item7]
myList = [item for item in itemList if (item != None)]
return count(myList)

Expression:
stack ( !Index2006! , !Index2007! , !Index2008! , !Index2009! , !Index2010! , !Index2011! , !Index2012! )
Attachment 29715

But I do not know how to calculate mean or count. I cannot divide sum value with a constant because there are always different number of fields with non Null values that need to be taken into account. Can anyone help me?

Best regards
Anne
Attached Thumbnails
Click image for larger version

Name:	tabel.png‎
Views:	N/A
Size:	23.9 KB
ID:	29714   Click image for larger version

Name:	calc.png‎
Views:	N/A
Size:	23.3 KB
ID:	29715  

Viewing all articles
Browse latest Browse all 2485

Trending Articles