top of page

Clean Integer Fields

The script deletes all fields whose type is an integer.

# Ehsan Momeni

from arcpy import env, CopyFeatures_management, ListFields, DeleteField_management

Input_Path = r"H:\Emomeni\Data.gdb"  # input data path


env.overwriteOutput = True  # to overwritght results
env.workspace = Input_Path  # setting workspace

feature_class = "cities"  # input feature class


new_name = feature_class + "_cleanField"  # new name for the new feature class

CopyFeatures_management(feature_class, new_name)  # copies the feature calss

fields = ListFields(new_name)  # all fields in the new feature class


for field in fields:
    if field.name != "OBJECTID":  # because objectID cannot be deleted
        if field.type == "Integer":  # if type is integer, it removes the field
            print("Type of %s is: %s" % (field.name, field.type))
            DeleteField_management(new_name, field.name)
            print       ("\t%s dropped." % field.name)


print ("\n\nAll fields with integer type removed from the %s." % new_name)
 

google_scholar1-300x150.png
ResearchGate.png
Ehsan Momeni ORCID GIS Remote Sensing Ur
Ehsan Momeni LinkedIn GIS Remote Sensing
ncbi-300x150.png
academia.png

(Information on this website may not be up to date)

bottom of page