Hi~~~Please refer to the illustration.
Above coding to output 0 1.I'd like to output 1 1.
I'd probably run a searchCursor to generate a list of unique values, then run the field calculator using that list of pregenerated unique values.
It may be easier to do this with a script rather than the Field Calculator. Ex:
import arcpy table = r"C:\TEMP\PYTHON\Test.gdb\XY" nameDict = {} with arcpy.da.SearchCursor(table, ["NAME"]) as cursor: for row in cursor: if row[0] not in nameDict.keys(): nameDict[row[0]] = 0 else: nameDict[row[0]] = 1 del cursor with arcpy.da.UpdateCursor(table, ["NAME", "Field"]) as cursor: for row in cursor: row[1] = nameDict[row[0]] cursor.updateRow(row) del cursor
Result:
Thank you for your reply.
I used your code.
The picture below is the printout I want. I used your code.I'd like to express all duplicate names by 1.
Are you saying the top picture is what you want - that makes sense to me - rather than the bottom picture?
looking at the code, I don't see how you got those results in the bottom picture either. Did you try the code I suggested?
Which field are you calculating on? Also unsure of the logic of that code compared to your expected output - doesn't make sense to me.
Anyway, as the code is executed on a per-row basis with the function, unique_list would have to be set to a global.
uniqueList = [] def isDuplicate(inValue): global uniqueList if inValue in uniqueList: return 1 else: uniqueList.append(inValue) return 0
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.