0

When I run the code below I don't get the output I'm seeking. The "max_proportion" field is assigned the text LEVELMEAN instead of the values for each row within the "LEVELMEAN" field when the conditional statement is met, "Highest" = 1. My else statement doesn't seem to be working either. Thanks.

fields ["Highest", "LEVELMEAN", "max_proportion"]
with arcpy.da.Update.Cursor(fc,fields) as cursor:
  for row in cursor:  
    if (row[0] == 1):
        row[2] = [1]
    else:
       row [2] = "<NULL>"
    cursor.updateRow(row)
6
  • 1
    What is row[2] = [1] supposed to do? Should it be row[2] = row[1]? And do you you really want the text "<NULL>" instead of an actual null value? – user2856 Jun 4 '20 at 6:17
  • row[2] = [1] is where I am attempting to set the blank field max_proportion to the values of LEVELMEAN field for each row. I don't really want "<NULL>", I'd prefer an actual null value. Didn't know how to execute that. Not sure if I understand the nuance of your second question. Thank you. All fields have the data type TEXT. – cbabis Jun 4 '20 at 13:10
  • Then if row == 1 will always be false, change to if row == "1" – BERA Jun 4 '20 at 16:19
  • I tried placing row == "1" – cbabis Jun 4 '20 at 20:50
  • Setting row [0] == "1" didn't work. In addition, I set the else statement to row [2] = None. To clarify row [0] == "1" won't always be false. When I run the code now I am receiving a TypeError value #2 - unsupported type: list. Not sure where to go next. – cbabis Jun 4 '20 at 20:55

Your Answer

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

Browse other questions tagged or ask your own question.