python - "Value is Required" on arcpy.CalculateField -
i'm pretty new python, , trying write script use in arcgis 10.1 (arcpy); basic idea add new field (francis), check values in several other fields, if null (-99) output 0 francis, otherwise run simple computation.however, i'm getting error , having trouble moving beyond it:
traceback (most recent call last):
file "c:\gislab2\python\take_home\part1\prelim_if2.py", line 28, in arcpy.calculatefield_management(output_feature_class, "francis", "", "python_9.3", "")
file "c:\program files\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3128, in calculatefield raise e
executeerror: failed execute. parameters not valid. error 000735: expression: value required failed execute (calculatefield).
here's code
# import arcpy module import arcpy print "start engines" # script arguments shapefile = "c:\\gislab2\\python\\take_home\\uscancer2000.shp" field_name = francis output_feature_class = "c:\\gislab2\\python\\take_home\\uscancer2000.shp" # local variables: uscancer2000__2_ = output_feature_class # process: add field arcpy.addfield_management(shapefile, "francis", "long", "", "", "", "", "nullable", "non_required", "") # process: calculate field arcpy.calculatefield_management(output_feature_class, "francis", "", "python_9.3", "") ## ### process: if-then check missing values ## if "cnt1"==-99: field_name=7 elif "cnt2"==-99: field_name=7 elif "cnt3"==-99: field_name=7 elif "pop1"==-99: field_name==7 elif "pop2"==-99: field_name=7 elif "pop3"==-99: field_name=7 else: field_name=("cnt1"+"cnt2"+"cnt3")/("pop1"+"pop2"+"pop3") print "done"
many in advance! david
the third parameter in arcpy.calculatefield_management
telling calculate. you're not passing there. test, replace line arcpy.calculatefield_management(output_feature_class, "francis", 5, "python_9.3", "")
, see if evaluates.
once runs, should using expression , codeblock calculations want. see calculate ranges (third) example here.
--alternative--
you may find easier use updatecursor. seems more work using calculatefield, can lot faster , saves trouble of writing out convoluted codeblock.
# import arcpy module import arcpy print "start engines" # script arguments shapefile = "c:\\gislab2\\python\\take_home\\uscancer2000.shp" field_name = "francis" # process: add field arcpy.addfield_management(shapefile, "francis", "long", "", "", "", "", "nullable", "non_required", "") fields = ["cnt1", "cnt2", "cnt3", "pop1", "pop2", "pop3", "francis"] # fields want available in cursor arcpy.da.updatecursor(shapefile, fields) cursor: row in cursor: # step through each row if not -99 in row: # check nulls # none found, math row[6] = (row[0] + row[1] + row[2]) / (row[3] + row[4] + row[5]) else: # nulls found, 0 out result row[6] = 0 cursor.updaterow(row) # save print "done"
Comments
Post a Comment