Dear All,
I want to calculate one field from another field e.g I want AAA- [FieldName], I want that AA will be change and give unique value e.g
AAA-[FieldName]
AAB-[FieldName]
ACA-[FieldName]
.....
etc
Thanks and regards
Bilal Alam
Solved! Go to Solution.
Can you elaborate on
I want to use the values from one of the field already available in data.
Do you have an existing field that is partially populated already? If so, do you want to use those values if they already exist but add new ones if they are missing? And, do you want to make sure any new values are not the same as existing values?
Dear Joshua and Bing,
Thanks for your kind help
I attach one picture which make you easy to understand.
In this picture fIeld _1 have value which have duplicate and I want to make unique code e.g AAC-4091
Try this in interactive Python Window, just update the value for lyr.
import arcpy
from itertools import product
from string import ascii_uppercase
lyr = # layer name or path to feature class
flds = ["Field_1", "Unique"]
incr = ("".join(i) for i in product(ascii_uppercase, ascii_uppercase))
with arcpy.da.UpdateCursor(lyr, flds) as cur:
for fld1, uniq in cur:
cur.updateRow([fld1, "A{}-{}".format(next(incr), fld1)])
Thanks Joshua it works thanks for your kind help
It stops when it works up to AZZ-222 if we need more then we have to change
cur.updateRow([fld1, "B{}-{}".format(next(incr), fld1)])
first letter to B
Is there any method that when A finished it automatically change A to B and so on
Thanks Joshua
The following code increments the first letter as well:
import arcpy
from itertools import product
from string import ascii_uppercase
lyr = # layer name or path to feature class
flds = ["Field_1", "Unique"]
incr = ("".join(i) for i in product(ascii_uppercase, ascii_uppercase, ascii_uppercase))
with arcpy.da.UpdateCursor(lyr, flds) as cur:
for fld1, uniq in cur:
cur.updateRow([fld1, "{}-{}".format(next(incr), fld1)])
Thanks Brother it works. I sincerely appreciate your help