I have a table (no spatial data) of cadastral data indicating monuments, where several plots have been combined into one single row. I want to disentangle them to join them with the base cadastral set. I would rather not do this manually. I have been trying to figure out a way to make duplicate rows with arcpy based on the number of "," in one field. This is how far I got:
with arcpy.da.UpdateCursor('input_fc','plots') as uCur:
for row in uCur:
list = []
if ',' in row[0]:
number = row[0].count(',')
r = range(1,number,1)
for i in r:
and that is where I got stuck trying to figure out how to tell it to duplicate the row as many times as there is a comma. Does anything like that exist?
You want an Insert Cursor, not an update cursor. Update is for editing rows that are already in the table, insert is for adding new ones.
I wrote this without testing, but the basic workflow is:
Also, am not sure if you're putting the rows into the same feature class or a new one, but either way you want an insert cursor.
rowList = []
with arcpy.da.SearchCursor(input_fc, 'plots') as sCur:
for row in sCur:
rowList.append(row)
with arcpy.da.InsertCursor('input_fc','plots') as iCur:
for row in rowList:
number = row[0].count(',')
if number > 1:
for i in range(1, number):
iCur.insertRow(row)
I also recommend asking python question in the Python Questions board for faster responses.