I would like to delete all rows which are joined to a layer from a csv table. Only the joined records which match (keep only matching records) should be deleted. After the records are deleted, the join should be removed again. I used the following script, but get the error: "cannot update join table".

arcpy.env.workspace = r"D:\skript\New File Geodatabase.gdb\test"



with arcpy.da.UpdateCursor("featurelayer", "OBJECTID") as cursor:
for row in cursor:
    if row[0] > 0:

arcpy.RemoveJoin_management ("featurelayer", "Errors")


Is this even possible?

  • Switch your join so that the rows you want to delete are the base and the features are the joined table. Use selection instead of a cursor. The selection persists after removing join, then call delete rows. Commented Jun 10, 2016 at 20:12
  • 1
    I'm pretty sure that ArcGIS / Arcpy cannot modify a CSV file. I've just tried it using both an update cursor and Delete Rows (as mentioned by @BenSNadler above) and it gives me an error for both. You may need to convert your CSV into an ArcGIS editable table before you can do any edits to it.
    – Midavalo
    Commented Jun 12, 2016 at 8:17
  • You are correct. Missed that detail Commented Jun 12, 2016 at 15:03
  • @Midavalo I think your comment would be fine as an answer.
    – PolyGeo
    Commented Sep 24, 2016 at 22:44

1 Answer 1


I know this is an old topic, but I had a similar issue to this today and I found a different solution. I ended up storing the ids of the items I wanted to delete in a list during a search cursor, and then removing the join, selecting by ID in (list) and then deleting the features.

no_change_ids = []
length_fields = ['out_fc.OBJECTID','out_fc.Shape_Length', old_fc + '.Shape_Length', 
working_layer + '.Shape_Length']
expression = u'{} = {}'.format(arcpy.AddFieldDelimiters("out_fc", "out_fc.CHANGE_TYPE"), "'TC'")
with arcpy.da.SearchCursor(out_fc, length_fields, expression) as cursor1:
    for row1 in cursor1:
        if row1[1] == row1[2] and row1[1] == row1[3]:
            print "No length change for row with ID:"+ str(row1[0])


expression = u'{} in ({})'.format(arcpy.AddFieldDelimiters("out_fc", "out_fc.OBJECTID"), ','.join(map(str,no_change_ids)))
arcpy.SelectLayerByAttribute_management(out_fc,"NEW_SELECTION", expression)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.