I am trying to select records in my table that have certain words in the "Name" field and then code them as 0 (not pharmacy) or 1 (pharmacy) This is just a test searching for two words to select non-pharmacies.
I am getting a:
ExecuteError: ERROR 000622: Failed to execute (Calculate Field). Parameters are not valid. ERROR 000623: Invalid value type for parameter field.
I don't know which variable is invalid. Any thoughts? I also do not know if the Calculate Field will work on only the records selected. I cannot get far enough to check that.
# import system modules import arcpy import random # set workspace environment myWorkspace = arcpy.env.workspace = "C:/PharmacyProtocol/tables" arcpy.env.overwriteOutput = True # set variables out_table = "VT_TRL_DLC.dbf" # set field variables fieldList = arcpy.ListFields(out_table) for field in fieldList: if field.name == "Name": nameF = field elif field.name == "Pharmacy": pharmF = field #create list of words that are NOT pharmacies noPharmWords = ['AMERICAN LEGION','BAR'] expression = 0 #find words in Name field, code Pharmacy as "0" if not already coded for codeWord in noPharmWords: #create SQL text clause fldName = '"Name"' endClause = "%'" SQLstr = fldName + " LIKE '%" + codeWord + endClause #select records from table with codeWord cursor = arcpy.da.SearchCursor(out_table, ["Name"], SQLstr) arcpy.CalculateField_management(out_table, pharmF, expression) del cursor