I have to calculate the mean of a field considering only values greater than 0.
Here is the table
Id | count |
1 | 12 |
2 | 9 |
3 | 6 |
4 | 5 |
5 | 0 |
6 | 3 |
7 | 4 |
8 | 0 |
9 | 2 |
10 | 2 |
11 | 0 |
12 | 3 |
13 | 2 |
14 | 2 |
15 | 0 |
16 | 3 |
17 | 0 |
Lots of ways to accomplish this, here is one:
from statistics import mean
tbl = # path to table
with arcpy.da.SearchCursor(tbl, "Count") as cur:
avg = mean(row[0] for row in cur if row[0] > 0)
How to do this using code block in the field calculator?