i'm kinda stuck with an UpdateCursor. This is what I'm trying to do: each cell of a grid stores multiple answers that were given in a survey. For each cell I must choose only ONE answer, the one that has the highest rates.
What I'm trying to do in my code is to select the rows that have the same value for the ID_GRID, compare the values in the PERCENT field, and update the FINAL_VALUE with the value from the VALUE field corresponding to the highest PERCENT value. In the example below, the answer 3310 has a rate of 76% > FINAL_VALUE for the selected results must be 3310.
My code takes only the last value in the SearchCursor and updates the whole FINAL_VALUE field with it:
myTable = r"D:\...." myFields = ['PERCENT', 'VALUE'] with arcpy.da.SearchCursor (myTable, "ID_GRID") as scursor: for srow in scursor: with arcpy.da.SearchCursor(myTable, myFields, "ID_GRID" + "= " + str(srow)) as sscursor: maxValue = None ID = None for ssrow in sscursor: if maxValue < ssrow: maxValue = ssrow ID = ssrow with arcpy.da.UpdateCursor(myTable, "FINAL_VALUE") as ucursor: for urow in ucursor: urow = ID ucursor.updateRow(urow)