I want my code to find the maximum value of a field from attribute table and return that as a the value for another field in another attribute table, trying to do this with search cursors and update cursor.
The search cursor seems to work fine, when I print the result is as expected, however, the update cursor does not return this value in the other attribute table but no errors are returned.
I am using ArcGIS Pro v. 3, arcpy with Python 3.
Here is my code:
fields = ["B1a_Score"]
all_rows = [i[0] for i in arcpy.da.SearchCursor(PA_Intersection,fields[0])]
max_val = max(all_rows)
print(max_val) #Correctly returns 4
AU = "AU_am"
field = ["B1a_Score"]
with arcpy.da.UpdateCursor(AU,field) as cursor:
for row in cursor:
row[0] = max_val
cursor.updateRow(row) #B1a_Score in AU is not updated to 4 instead reads <null>
del cursor
CalculateField
would be faster (since it's C++). I wonder what would happen if you usedcursor.updateRow([max_val])