How to calculate mean of a field considering only values ​​greater than 0 in ArcGIS field calculator/ in Arcpy?

509
2
04-29-2021 05:51 AM
badrinathkar
New Contributor III

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

0 Kudos
2 Replies
JoshuaBixby
MVP Esteemed Contributor

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)
badrinathkar
New Contributor III

How to do this using code block in the field calculator?

0 Kudos