I'm trying to create a Python script to automate simplifying some feature classes (shapefiles). The data table for my shapefiles look like this (all of the fields except the first four are SHORT):
FID Shape* GEOID10 EMS_ORI A_CO01 A_CO05 A_CO06 A_CO11 ___________________________________________________________________________________ 0 Polygon 421110218001027 E56001 99 23 99 17 1 Polygon 421110218001231 E56001 99 24 30 15 2 Polygon 421110218001028 E56001 99 24 99 16 3 Polygon 421110218001035 E56001 99 24 99 99
and so on. I am trying to find an easy way to delete an entire field if it only contains the value "99" for every row. In this example, I would want to delete the A_CO01 field because all features in this shape file have a value of 99 there. I do not want to delete A_CO06 or A_CO11, because at least one feature has a value other than 99 in each of those fields. My shapefiles have thousands of features, so I tried to script this with Python in an instant Python window in ArcCatalog. I'm only a novice at Python, so I know I'm missing something easy, but here's what I tried:
import arcpy
fc = 'E:/EMS500_Polygons.shp'
fields = arcpy.ListFields(fc)
for field in fields:
if (field.name == "FID" or field.name == "Shape" or field.name == "GEOID10" or field.name == "EMS_ORI"):
continue
else:
if (field.type = "Integer" and min(field) == 99):
arcpy.DeleteField_management(fc, field)
This gives me a syntax error on line 10: if (field.type = "Integer" and min(field) == 99):
. What I'm trying to do is delete any field where the MIN value of the entire field is 99 (this value is a "placeholder"; valid values for this field range from 1 to 93).
if (field.type = "Integer"...
. I fixed it toif (field.type == "Integer" and min(field) == 99):
, but now it doesn't delete any of the fields, so I'm still missing something.