This is my first time using python in ArcGIS. I have a gdb of about 100 feature classes, and need to get Zonal Statistics for each. I'm using a textbook, and got this so far:

import arcpy
from arcpy import env
env.workspace = 'D:\Documents\Archaeology\Dissertation\Data\GIS\Places_Bounds\Places\Exploded_Bilinear\Argolid.gdb'
fclist = arcpy.ListFeatureClasses ("ID_*")
for fclist: 
    arcpy.sa.ZonalStatistics ("fclist", "place_id", "pelop1arcm34b", "MEAN", "NODATA")

The error is coming from line 6. I am assuming my trouble is defining the input for the zonal statistics -- I want it to refer to the geodatabase set in the workspace, and loop through the whole dataset (about 100 feature classes). For reference: place_id is the unique identifier, and pelop1arcm34b is the DEM.

  • 2
    You should add an r in front of the path. Otherwise the backslashes can cause problems. For example r'C:\database.gdb'. So the DEM is located in the workspace database and all the feature classes have the same zone field name?
    – BERA
    Feb 6, 2018 at 20:11

1 Answer 1


I corrected your code for you. After each line you find a comment to show you what was corrected. Also reading about about for loops, the range and len functions can help you understand the changes.

import arcpy
#from arcpy import env #this line can be removed
arcpy.env.workspace = r'D:\Documents\Archaeology\Dissertation\Data\GIS\Places_Bounds\Places\Exploded_Bilinear\Argolid.gdb' #called arcpy.env
fclist = arcpy.ListFeatureClasses("ID_*") #removed whitespace
for i in range(len(fclist)): #corrected your loop
    outraster = arcpy.sa.ZonalStatistics (fclist[i], "place_id", "pelop1arcm34b", "MEAN", "NODATA") #corrected reference to the items you are iterating over by retrieving it from the fclist by its index
    outraster.save("outraster" + str(i)) #save the outputraster with the name 'outraster1' 'outraster2' etc.
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – PolyGeo
    Feb 7, 2018 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.