if [Name] = "Orange Lake" then [Pg_Number] = 5, 6, 7, 8, 9, 10... if [Name] = "Green Lake" then [Pg_Number] = 11, 12, 13, 14, 15..." and so on...
new_table = "c:\users\craig.mcdade\table.dbf" # new table
new_table = r"c:\users\craig.mcdade\table.dbf"
arcpy.insertCursor(new_table) ... with arcpy.da.InsertCursor(key, val in tableDict.iteritems()) as cursor: ... for row in cursor: ... row = insertCursor.newRow() ... row.setValue(keyField, key) ... row.setValue(valField, ', '.join(val)) ... insertCursor.insertRow(row)
insertCursor = arcpy.da.InsertCursor(os.path.join(outPath, new_table), [keyField, valField]) for key, val in tableDict.iteritems(): insertCursor.insertRow((key, ', '.join(val)))
import arcpy, os table = r"c:\users\craig.mcdade\GridforPython.dbf" # source_table new_table = r"c:\users\craig.mcdade\table.dbf" # new table tempTable = r'\\in_memory\temp_table' outPath = r'\\in_memory\outPath' keyField = 'NAME' valField = 'Pg_Number' tableDict = {} arcpy.MakeTableView_management(table, tempTable) with arcpy.da.SearchCursor(tempTable, [keyField, valField]) as cursor: for row in cursor: tableDict.setdefault(row[0], []).append(row[1]) open("new_table","w") insertCursor = arcpy.da.InsertCursor(os.path.join(outPath, new_table), [keyField, valField]) for key, val in tableDict.iteritems(): insertCursor.insertRow((key, ', '.join(val)))
import os import arcpy table = r"c:\users\craig.mcdade\GridforPython.dbf" # source_table new_table = r"table.dbf" # new table name + extension only tempTable = r"\\in_memory\temp_table" outPath = r"c:\users\craig.mcdade" # path to output location on disk keyField = 'NAME' valField = 'Pg_Number' tableDict = {} arcpy.MakeTableView_management(table, tempTable) with arcpy.da.SearchCursor(tempTable, [keyField, valField]) as cursor: for row in cursor: tableDict.setdefault(row[0], []).append(row[1]) insertCursor = arcpy.da.InsertCursor(os.path.join(outPath, new_table), [keyField, valField]) for key, val in tableDict.iteritems(): insertCursor.insertRow((key, ', '.join(val)))
for key, val in tableDict.iteritems(): insertCursor.insertRow((key, ', '.join(str(item) for item in val))