Select to view content in your preferred language

How to update a field with values from another field in table?

1754
2
Jump to solution
02-11-2014 01:27 AM
808707
by
Deactivated User
Hello,

I have a big dataset with a field of values ranging from 1 to 10.

I want to update another field with a string depending on which value is in the other field.

So for example:

1 = Woodland
2 = Arable
3 = River, etc etc

I was wondering how I would go about this in arcgis?

I have done something similar with SQL using an IIF function but am struggling with how to figure it out.

Thanks for any help
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Hi Mark,

Here is an example on how to do this using the arcpy.da.UpdateCursor (10.1 or beyond is required):

import arcpy from arcpy import env env.workspace = r"C:\temp\python\test.gdb"  fc = "featureClass"  with arcpy.da.UpdateCursor(fc, ["field1", "field2"]) as cursor:     for row in cursor:         if row[0] == 1:             row[1] = 'Woodland'         if row[0] == 2:             row[1] = 'Arable'         ......             .....         cursor.updateRow(row)  del cursor, row

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Mark,

Here is an example on how to do this using the arcpy.da.UpdateCursor (10.1 or beyond is required):

import arcpy from arcpy import env env.workspace = r"C:\temp\python\test.gdb"  fc = "featureClass"  with arcpy.da.UpdateCursor(fc, ["field1", "field2"]) as cursor:     for row in cursor:         if row[0] == 1:             row[1] = 'Woodland'         if row[0] == 2:             row[1] = 'Arable'         ......             .....         cursor.updateRow(row)  del cursor, row
0 Kudos
808707
by
Deactivated User
Hi Mark,

Here is an example on how to do this using the arcpy.da.UpdateCursor (10.1 or beyond is required):

import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"

fc = "featureClass"

with arcpy.da.UpdateCursor(fc, ["field1", "field2"]) as cursor:
    for row in cursor:
        if row[0] == 1:
            row[1] = 'Woodland'
        if row[0] == 2:
            row[1] = 'Arable'
        ......
            .....
        cursor.updateRow(row)

del cursor, row


Thankyou very much that worked a treat 🙂
0 Kudos