0

My issue is that I am getting an error statement that states the following:

     row[0] = row[2] / row[1] * 100
     TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

Here is the script I'm using to run the operation

#variables
 fieldname1 = "acres2"
 fieldname2 = "ac_std2"
 fieldtype = "DOUBLE"
 where_clause_calc = """"acres2" IS NOT NULL"""


#newfields

 arcpy.AddField_management(fc, fieldname1, fieldtype)
 arcpy.AddField_management(fc, fieldname2, fieldtype)



#float
 with arcpy.da.UpdateCursor(fc, ["StatedAcre", "acres2"]) as cursor:
    for row in cursor:
        try:
            row[1] = float(row[0])
            cursor.updateRow(row)
        except:
            row[1] = -999
            cursor.updateRow(row)

 del cursor


 #calculate
 with arcpy.da.UpdateCursor(fc, ["ac_std2","acres2","Area"], where_clause_calc) as cursor:
    for row in cursor:
        if row[1] > 0.00:
            if row[1] < row[2]:
                row[0] = row[1] / row[2] * 100
                cursor.updateRow(row)
            else:
                row[0] = row[2] / row[1] * 100
                cursor.updateRow(row)

        else:
            row[0] = -999


 del row
 del cursor

When I create both fields being used to calculate, I set the field type to DOUBLE. When I open the table in ArcMap the field properties reflect this. What's especially odd is that the updates are performed for about 1/4 of the rows in the table. My questions are why is this error occurring while both field types are DOUBLE, and what can I do to fix this issue?

4
  • 1
    One of your fields has one or more null values in it.
    – PolyGeo
    Commented Jul 20, 2018 at 22:51
  • I have other queries that filter out nulls. Additionally, I added a try and except loop, so I could see which rows weren't being updated and all the necessary columns contain values. Commented Jul 20, 2018 at 23:02
  • You were right! I ignoring one of the columns. My bad, thanks for the help! Commented Jul 20, 2018 at 23:07
  • 1
    As per gis.meta.stackexchange.com/questions/4312 I recommend not using try/except when testing because it can mask otherwise useful error messages. When you present error messages please always show the full error message, including line number, that you get from running the exact code that you present.
    – PolyGeo
    Commented Jul 20, 2018 at 23:08

0

Browse other questions tagged or ask your own question.