I'm having issues setting a row value to 0 when joining a csv to a shapefile. When the shapefile value is not in the csv, the row is getting set to 0 instead of null. This is a huge problem as i'm showing 0 change instead of no data. I tried row.setValue(field, None) and row.setNull(field) and both produce the same result. In the .dbf file of the shapefile, there is no value but in the UI attribute table a 0 is shown.

arcpy.AddField_management(shpfile, "TEST", "DOUBLE", field_is_nullable = 'NULLABLE')

newcols = ["TEST"]

with open(csvfile, 'rb') as csvfile:
    lib = dict()
    csvfile = csv.reader(csvfile, delimiter = ",")
    csvfile.next() #skip the headers
    for line in csvfile:
        lib[line[csvjoinindex]] = lib.get(line[csvjoinindex],line[csvstartfield:])
rows = arcpy.UpdateCursor(shpfile)
for row in rows:
    shpjoinval = str(row.getValue(shapefilejoincol))
        vals = lib.get(shpjoinval)
        for ind, field in enumerate(newcols):
        for ind, field in enumerate(newcols):

You cannot output a Null value in a shapefile to a numeric field. This is part of the shapefile specification, so the specification will override every attempt you make to set a Null value. You have to output your data to a gdb (file gdb is best) feature class to use Null values in numeric fields.

The help under Geoprocessing considerations for shapefile output states:

"Null values are not supported in shapefiles. If a feature class containing 
 nulls is converted to a shapefile, then the null values will be
 changed into the following:

Number - When tool requires a NULL, infinity, or NaN (Not a Number) to be output.   -1.7976931348623158e+308 (IEEE standard for the maximum negative value)
Number (all other geoprocessing tools)  0
Text    " " (blank — no space)
Date    Stored as zero, but displays "<null>".""
  • 9.3 Help?? That page was last updated almost 7 years ago, haha. Here is the latest, which covers a bit more. +1!
    – Paul
    Sep 23 '15 at 23:01
  • Thanks for the more current help reference. The 9.3 reference came up as the first choice in Google, so the new help has not had nearly as many hits yet. Anyway, they both show that this limitation is nothing new. Sep 23 '15 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.