Hi,
is there a simple way in ArcGis Pro of combining multiple attribute1 values (with comma as a delimiter) into one cell based on attribute2 values. Here is a simple example:
As a result, I would like to get a table with two lines
attr2 | attr1
1 | "1"
2 | "2, 5"
Thank you for any help. I believe there is some very simple solution, but I did not find it 😕
Best from
T.
Solved! Go to Solution.
this could be the solution (I believe it can be way shorter)
outDict = {}
columns = ['treeNumber', 'parcel']
curObj = arcpy.da.SearchCursor("tmpIntersect", columns) # tmpIntersect is original table
for row in curObj:
if row[0] in outDict:
outDict[row[0]].append(row[1])
else:
outDict[row[0]] = [row[1]]
arcpy.CreateTable_management(gdb, outputT)
arcpy.AddField_management(gdb+"\\"+outputT, "itemNumber", "SHORT")
arcpy.AddField_management(gdb+"\\"+outputT, "parcel", "TEXT")
rows = arcpy.InsertCursor(outputT, ["itemNumber","parcel"])
for x, y in outDict.items():
row = rows.newRow()
row.setValue("itemNumber",x)
row.setValue("parcel", ", ".join(y))
rows.insertRow(row)
arcpy.Delete_management(gdb+"\\tmpIntersect")
this could be the solution (I believe it can be way shorter)
outDict = {}
columns = ['treeNumber', 'parcel']
curObj = arcpy.da.SearchCursor("tmpIntersect", columns) # tmpIntersect is original table
for row in curObj:
if row[0] in outDict:
outDict[row[0]].append(row[1])
else:
outDict[row[0]] = [row[1]]
arcpy.CreateTable_management(gdb, outputT)
arcpy.AddField_management(gdb+"\\"+outputT, "itemNumber", "SHORT")
arcpy.AddField_management(gdb+"\\"+outputT, "parcel", "TEXT")
rows = arcpy.InsertCursor(outputT, ["itemNumber","parcel"])
for x, y in outDict.items():
row = rows.newRow()
row.setValue("itemNumber",x)
row.setValue("parcel", ", ".join(y))
rows.insertRow(row)
arcpy.Delete_management(gdb+"\\tmpIntersect")