hello, I have a polyline shapefile, and I need to calculate the mean value of one column of its attribute table using arcpy.
Any suggestion?
import numpy as np from arcpy.da import SearchCursor values = np.mean([row[0] for row in SearchCursor(fc, "Shape_Length")])
An equivalent but slower method, if there are no nulls (an extra hoop to jump through is necessary if there are nulls)
As in Summary Statistics (Analysis)—ArcGIS Pro | Documentation
or is it something different you are looking for?
or perhaps
import numpy as np from arcpy.da import TableToNumPyArray fc = r"C:\Git_Dan\npgeom_bak\Project_npg\npgeom.gdb\Ontario_singlepart" arr = TableToNumPyArray(fc, "Shape_Length", skip_nulls=True) np.mean(arr["Shape_Length"]) 84684.37997765756
I will try this one.
Thanks a lot.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und vieles mehr. Neu hier? Erstelle ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.