Using LIKE in a For Loop with UpdateCursor
I would isolate the class you are after rather than searching for it. Then, simply assign row[1]
that isolated value. For example:
in_table = 'l12wm_agsup02.img'
field_names = ['Class_Name', 'crop']
with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
for row in cursor:
row[1] = row[0].split("-")[2].split(".")[0]
cursor.updateRow(row)
This does not have to be done in a python script, it can be done simpler by using the calculate field tool as shown below:
If you want to run this as python the code would be:
arcpy.CalculateField_management("myRaster","crop","cropnumber( !class! )","PYTHON_9.3","""def cropnumber(s):/n if s.find("-1.") != -1:/n return 1/n elif s.find("-2.") != -1 :/n return 2/n else:/n return -999""")