I want to delete specific values in a field. In the code below I used an update cursor to update Wk4_May18May21_ACTIV with the values from Wk3_May11May14_ACTIV that had the word "Planned" in them. Now I want to delete the values from Wk3_May11May14_ACTIV that have the word "Planned" in them but using a delete cursor deletes the entire row. I just want the values in the column deleted (they can be left as null or empty). Also, all of this code is being used in Jupyter notebooks and the data being changed is on AGOL.
with arcpy.da.UpdateCursor (fc, ['SITE_ID', 'Wk3_May11May14_ACTIV','Wk4_May18May21_ACTIV'], "Wk3_May11May14_ACTIV LIKE '%Planned%'") as cursor:
for row in cursor:
row[2] = row[1]
cursor.updateRow(row)
Any help would be great, I am fairly new to Python.
Solved! Go to Solution.
Then set row[1] = None. Using the update cursor you can move the value of row[1] into row[2], then delete (set to None) the value in row[1].
with arcpy.da.UpdateCursor (fc, ['SITE_ID', 'Wk3_May11May14_ACTIV','Wk4_May18May21_ACTIV'], "Wk3_May11May14_ACTIV LIKE '%Planned%'") as cursor:
for row in cursor:
row[2] = row[1]
row[1] = None
cursor.updateRow(row)
if the code works for replacement and the query works, then did you try row[2] = None
I'm not trying to delete anything from row[2] it's the values in row[1] that I was to delete.
same principle, switch the assignment of None
Then set row[1] = None. Using the update cursor you can move the value of row[1] into row[2], then delete (set to None) the value in row[1].
with arcpy.da.UpdateCursor (fc, ['SITE_ID', 'Wk3_May11May14_ACTIV','Wk4_May18May21_ACTIV'], "Wk3_May11May14_ACTIV LIKE '%Planned%'") as cursor:
for row in cursor:
row[2] = row[1]
row[1] = None
cursor.updateRow(row)
Amazing thank you!