Reputation: 13
I am writing a python script to create unique ID's. I am working to change empty values(9999) to the next available id. Here is what my data looks like. There is a North/South descriptor, a East/West descriptor, a section number, and the unique number for the final two values of the ID. All columns are strings except the final ID (which is a long int.
I have been able to concatenate the first 3 values but am having trouble creating the unique last two digits for each.
I originally was using pandas and it was quite simple. Here was my the gist of my script:
fields = ['ID','NS', 'EW','Sec']
df = pd.read_excel(in_file, usecols=fields)
df['instance'] = df.groupby(['Twnshp', 'Rng', 'Section']).cumcount() + 1
def create_unique_id(row):
twn_id = '1' + row['TwnNum'] if row['TwnDir'] == 'N' else '0' + row['TwnNum']
rng_id = '1' + row['RngNum'] if row['RngDir'] == 'W' else '0' + row['RngNum']
sec_id = row['Section'].zfill(2)
inst_id = str(row['instance']).zfill(2)
return twn_id + rng_id + sec_id + inst_id
I am now trying to create a tool within ArcGIS Pro and need help with the count using lists instead, because pandas does not integrate all that well with the program.
I am thinking it might look something along the lines of.(data is just for sample purposes)
list_NS= [105,106,103,002,104,001,105,106,103,002,104,001,105]
list_EW = [101,106,104,003,005,109,101,106,104,003,005,109,101]
list_sec=[18,12,08,14,07,02,18,12,08,14,07,02,18]
list_id = [1051011801,1061061201,1031040801,20031401,1041050701,11090201,9999,9999,9999,9999,9999,9999,9999]
#need some way to group them by the first 8 values
#Splice off last two values for each id in that group and start a counter
#create an if statement to see if value id is 9999(would make the grouping harder?)
# if it is 9999 then replace it with the next available id for that group.
Just looking for a creative way to keep a counter for each group. Any help is appreciated. Thanks!
Upvotes: 0
Views: 70