Solved! Go to Solution.
Does anyone have a Python script to populate a field based on the code of another field in the same table?
f(!CODEFIELD!)
def f(code): codelist = ['a','b','c'] valuelist = [10,20,30] value = valuelist[codelist.index(code)] return value
This may be simple but I am only a beginner. Does anyone have a Python script to populate a field based on the code of another field in the same table? Or do have any recommendations where I might find a script?
Thank you
Pam
import arcpy cur = arcpy.UpdateCursor(r"c:\your file") #put in your file path here for row in cur: row.fieldName1 = row.fieldName2 #here I am copying the data from one field to another, just add your own code here. cur.updateRow(row) #transfer the row changes from memory to the table
Does anyone have a Python script to populate a field based on the code of another field in the same table?
f(!CODEFIELD!)
def f(code): codelist = ['a','b','c'] valuelist = [10,20,30] value = valuelist[codelist.index(code)] return value