Is there an easy way to calculate all
Null integer fields to
0 in a GDB?
Null values and field calculating each column to
0 is not a viable option as I need to do this for a few hundred columns across multiple layers.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
You can do this for many fields with some Python. This is a stand alone example, but it'd be easy to write this into a script/Python toolbox. Or you could embed this into another loop and do this on a list of feature classes/tables.
Keep in mind this approach will make the changes to all short/long integer fields:
import arcpy features = 'SomeGDB.gdb/SomeFeatureClass' fields = arcpy.ListFields(features) fnames = [x.name for x in fields if x.type in ['Integer','SmallInteger']] with arcpy.da.UpdateCursor(features, fnames) as rows: for row in rows: updated = False # keep track if we actually update something for v in range(len(fnames)): if row[v] is None: row[v] = 0 updated = True # only update the row if we changed something if updated: rows.updateRow(row)