Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to identify duplicate records from a field and then change these records so they become unique (eg A,B,C, or 1,2,3) and assign this to the end of the text (eg F3241 A56_A or F3241 A56_1). I've tried the scripts that are in this forum but can't get these to work or not sure if they will give me the result I'm after. Any input into to this would be greatly appreciated.

share|improve this question
Can you provide more details, eg some example data, what format your data is in, the GIS you are using, etc. – sgrieve Sep 19 '12 at 8:06
Thanks for the reply. I'm using a shapefile and the field type is a string. I'm using v10 and will attach some sample data when I'm back in the office. Thanks again – user10322 Sep 19 '12 at 13:40
Rather than "then change these fields so they become unique" do you mean "then change these records so they become unique"? – Stephen Lead Sep 19 '12 at 23:26
My apologies Stephen you are correct, I do mean records and not fields. Also I'm quite new to this site and was wondering how you can attach screenshots/data to comments? – Chris Graves Sep 24 '12 at 3:01
@ChrisGraves you can't add screenshots to a comment, but if you press the Help button under the "Add Comment" button you'll see the allowed markup (eg bold, italic, hyperlink). To attach a screenshot, Edit your original post then use the "image" icon to upload a screenshot to the post. – Stephen Lead Sep 24 '12 at 3:24

You could use an update cursor for this:

attribs = {}
rows = arcpy.UpdateCursor (your_shapefile, "WHERE SQL", "", "FIELDS;SEPARATED;BY;SEMICOLON", "SORTFIELD A; SORTFIELD2 D")
##UpdateCursor (dataset, {where_clause}, {spatial_reference}, {fields}, {sort_fields})
for row in rows:
    if row.FIELD_OF_INTEREST in attribs:
        attribs[row.FIELD_OF_INTEREST] += 1
        attribs[row.FIELD_OF_INTEREST] = 1
    row.FIELD_OF_INTEREST = "%s_%i" % (row.FIELD_OF_INTEREST, attribs[row.FIELD_OF_INTEREST])
share|improve this answer
Thankyou for your help with this very much appreciated. I've tried the above update cursor script but receive the following error after the first line:>>> import arcpy >>> attribs = {} >>> rows = arcpy.UpdateCursor("C:\ProjectData\Acoustics\Model_19thSept\Data\BuildingsDCDB_I‌​ntersect.shp", "WHERE", fields="FIELDS;SEPARATED;BY;SEMICOLON", "SORTFIELD A; SORTFIELD2 D") SyntaxError: non-keyword arg after keyword arg – Chris Graves Sep 24 '12 at 2:46
Sorry, my bad - code updated above (as the error says, I didn't put in the keyword for the sorfields)... Also, if you don't have a where string, replace "WHERE SQL" with an empty string, i.e. "". – om_henners Sep 24 '12 at 2:59
Thanks again for your input. I've done what I think is correct but receive an SyntaxError: invalid syntax (see below). What is the first bit of the script doing? My understanding is its calling on the dataset and sorting the field? What I'm trying to do is find the duplicate records in a field called 'PARCEL_ID' and then place 1,2,3,4 (or a,b,c etc) to those duplicates in that same field. Sorry for the long comment :-) – Chris Graves Sep 24 '12 at 6:23
sorry forgot the script:>>> rows = arcpy.UpdateCursor ("C:\ProjectData\Acoustics\Model_19thSept\Data\BuildingsDCDB_Intersect.shp",{""}‌​,{"GDA94"},{"FIELDS;SEPARATED;BY;SEMICOLON", "SORTFIELD A; SORTFIELD2 D"}) SyntaxError: invalid syntax – Chris Graves Sep 24 '12 at 6:23
No worries @ChrisGraves - in the comment the {} mean that the argument is optional. In your case you don't need a spatial reference, the only field you want back is PARCEL_ID and (maybe, but not really necessary) you want to sort on PARCEL_ID. As such the line of code will be rows = UpdateCursor("C:\ProjectData\Acoustics\Model_19thSept\Data\BuildingsDCDB_Interse‌​ct.shp", "", "", "PARCEL_ID", "PARCEL_ID A") though rows = UpdateCursor("C:\ProjectData\Acoustics\Model_19thSept\Data\BuildingsDCDB_Interse‌​ct.shp") would work just as well in your case. – om_henners Sep 24 '12 at 6:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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