I'm trying to find a way of adding <Null> to a record when there a change in the data sequence on another field attribute...?
I've been trying to adapt this code to achieve this, but I'm struggling.
import arcpy from arcpy import da vertices = "dataset" #set firstRow variable to true firstRow = True with arcpy.da.UpdateCursor(vertices, ["Shape", "Line_ID", "angle"]) as cursor: for row in cursor: name2 = row[1] #check if its the first row if firstRow == True: name1 = name2 #set firstrow to false firstRow = False continue row[2] = str(name1 - name2) name1 = name2 cursor.updateRow(row)
The result should be something like this:
I'm rather new to UpdateCurser, so, generally don't know how it works.
Solved! Go to Solution.
Does this work for you?
import arcpy
from arcpy import da
vertices = "dataset"
#set firstRow variable to true
firstRow = True
with arcpy.da.UpdateCursor(
vertices,
["Line_ID", "angle"]
sql_clause=(None, "ORDER BY LINE_ID, OBJECTID")
) as cursor:
lid_prev, ang_prev = next(cursor)
cursor.updateRow([lid_prev, None])
for lid, ang in cursor:
if lid != lid_prev:
cursor.updateRow([lid, None])
lid_prev = lid
Does this work for you?
import arcpy
from arcpy import da
vertices = "dataset"
#set firstRow variable to true
firstRow = True
with arcpy.da.UpdateCursor(
vertices,
["Line_ID", "angle"]
sql_clause=(None, "ORDER BY LINE_ID, OBJECTID")
) as cursor:
lid_prev, ang_prev = next(cursor)
cursor.updateRow([lid_prev, None])
for lid, ang in cursor:
if lid != lid_prev:
cursor.updateRow([lid, None])
lid_prev = lid
Much appreciated Joshua. Thank You.
If my suggestion worked, please mark it correct to close the question.