Hello, I'm a beginner in ArcPy and I want to perform some tasks using ArcPy but I am not getting results. Using ArcMap I have an attribute field, with like 13K number of records. The Layer is called Splicepoint.
I would like to change the names of a fields in the attribute table called Station ID (to have a sequential name that I have created. In 11 character long name – SPLCNVA1A001, SPLCNVA1A002, SPLCNVA1A003…… SPLCNV1B001….. SPLCNV1Z001….. SPLCNV1Z999) They are all related to the field of SUBTYPE (FOSC). Also, I need to skip I and O’s to avoid confusion .
This is just a one time code that would keep changing the sequence.
How/where are you trying to accomplish this? In ArcMap with select and calculate field GP tools, or in a python window?
Also, you say sequential name that 'you have created'. Do you have a separate lookup table or are you wanting it to start with the first FOSC row and append the sequential number to the end of "SPLCNV" for the Station ID field value?
Need some kind of clarification as your examples show different values (other than the sequential number) appended to the end. ( A1A00#, 1B00#, 1Z00# ) or are these typos as there doesn't seem to be a pattern other than the last three numbers (where are the A's, B's and Z's coming from).
R_
On ArcMap Python window.
Yes I am starting with " with the first FOSC row and append the sequential number to the end of "SPLCNV" for the Station ID field value?"
okay so the pattern is
SPLCNV1A001,
SPLCNV1A002,
SPLCNV1A003……
SPLCNV1B001….. all the way to "Z"
SPLCNV1Z001…..
SPLCNV1Z999.... and eventually end at 1Z
SPLCN = SPLICE
NV = STATE which is Nevada
and then 1A and 001 (number up to 999)
THANK YOU.
@JMerryline wrote:I would like to change the names of a fields in the attribute table called Station ID (to have a sequential name that I have created.
Have you already coded the logic in Python to generate this sequential value?
Run this in the Python Window (change the first three lines):
fc = "TestPolygons" # path to the feature class or name of the layer
field = "TextField1" # field you want to edit
sql = "Subtype = 'FOSC'" # select the features you want to edit
import string
letters = list(string.ascii_uppercase)
letters.remove("I")
letters.remove("O")
with arcpy.da.UpdateCursor(fc, field, sql) as cursor:
for i, row in enumerate(cursor):
letter = letters[int(i/1000)]
number = i % 1000
new_id = "SPLCNV1{}{:03}".format(letter, number)
cursor.updateRow([new_id])
This will fail after Z999!