Is it possible to iterate fields in a table to remove Null values and spaces (where there is no value)? In other words, I would like to replace Null and " " with "" (no space).
Cobbling arcpy scripts, I have this:
import arcpy
fc = "{path to geodatabase and feature class}"
fieldList = arcpy.ListFields(fc)
for field in fieldList:
with arcpy.da.UpdateCursor(fc, [fieldList]) as cursor:
for row in cursor:
if row[0] == None:
row[0] = ''
elif row[0] == ' ':
row[0] = ''
cursor.updateRow(row)
print "Processing complete"
I'm aware of using "remove" in the field calculator, but you have to go field by field. I'd like to do this for the whole table.
Best Answer
I think you've got it the wrong way around. Not
for field in fieldList
thenfor row in cursor
, ratherfor row in cursor
andfor field in fieldList
except you will need to index properly... you're only trying to adjust the first field in the fieldList with row[0].Be aware that no checking is being done for field types; trying to set '' into a numeric field will cause this script to crash hard!