1

I work on a point layer which contains 2000 features. I'm trying to change all the values "industry" in field "name" only (it has 1000 features of industry values) into "landUse". The FID of the those features start from FID 500 til FID 1500 in running order.

In this code, continually to Change specific rows in attribute table using Arcpy in ArcGIS 10.3

import arcpy

lyrName = r"G:\PROJECTS\gis\layers\New File Geodatabase.gdb\digum2"
with arcpy.da.UpdateCursor(lyrName, ["name1", "OID@"]) as cursor:
    for row in cursor:
        if row[1] in (70, 71, 72):
           row[0] = 'no land use'
           cursor.updateRow(row)
           print """Updated row {}""".format(row[1])

I can change several rows, but I can't write 1000 number in the brackets.

How can I change those 1000 features values only using Arcpy?

0

1 Answer 1

3

You should either add a where clause in the cursor (recommended) or check the value of the name field when iterating the rows:

with arcpy.da.UpdateCursor(lyrName, ["name"], """name = 'industry'""") as cursor:
    for row in cursor:
      row[0] = 'landUse'
      cursor.updateRow(row)

with arcpy.da.UpdateCursor(lyrName, ["name"]) as cursor:
    for row in cursor:
      if row[0] == 'industry':
         row[0] = 'landUse'
         cursor.updateRow(row)
2
  • So, you cannot select features using the name attribute? You want to assign an 'industry' value to a range of features based on their ID? Commented Jan 4, 2018 at 12:24
  • if you can select features using the 'industry' value, no need to select based on the objectid Commented Jan 4, 2018 at 12:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.