import arcpy from arcpy import env env.workspace = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" table = "WAYNE" list = [] with arcpy.da.SearchCursor(table, ["FULL_ADDRESS_NAME"]) as cursor: for row in cursor: list.append(row[0]) del row, cursor with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows: for updateRow in updateRows: nameValue = updateRow[0] if nameValue in list: updateRow[1] = lutDict[nameValue] updateRows.updateRow(updateRow) del updateRow, updateRows
Solved! Go to Solution.
import arcpy from arcpy import env env.workspace = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" table = "WAYNE" list = [] with arcpy.da.SearchCursor(table, ["FULL_ADDRESS_NAME"]) as cursor: for row in cursor: list.append(row[0]) del row, cursor with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows: for updateRow in updateRows: nameValue = updateRow[0] if nameValue in list: updateRow[1] = lutDict[nameValue] updateRows.updateRow(updateRow) del updateRow, updateRows
import arcpy from arcpy import env env.workspace = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" table = "WAYNE" uniqueValues = {} newID = 1 with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows: for row in updateRows: nameValue = row[0] if nameValue in uniqueVals: row[1] = uniqueValues[nameValue] else: newID += 1 uniqueValues[nameValue] = newID row[1] = newID updateRows.updateRow(row) del row, updateRows
import arcpy from arcpy import env env.workspace = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" table = "WAYNE" list = [] with arcpy.da.SearchCursor(table, ["FULL_ADDRESS_NAME"]) as cursor: for row in cursor: list.append(row[0]) del row, cursor with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows: for updateRow in updateRows: nameValue = updateRow[0] if nameValue in list: updateRow[1] = lutDict[nameValue] updateRows.updateRow(updateRow) del updateRow, updateRows
import arcpy from arcpy import env env.workspace = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" table = "WAYNE" uniqueValues = {} newID = 1 with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows: for row in updateRows: nameValue = row[0] if nameValue in uniqueVals: row[1] = uniqueValues[nameValue] else: newID += 1 uniqueValues[nameValue] = newID row[1] = newID updateRows.updateRow(row) del row, updateRows
The Summary Statistics tool works exactly like frequency if you specify the inputs correctly, and it only requires ArcGIS Basic (ArcEditor). The python syntax is available at the link.
Summary statistics is written in C++. It will be significantly faster than any Python solution.
import arcpy from arcpy import env env.workspace = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" table = "WAYNE" uniqueValues = {} values = [] newID = 1 with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows: for row in updateRows: nameValue = row[0] values.append(nameValue) if nameValue in uniqueVals: row[1] = uniqueValues[[nameValue]] else: newID += 1 uniqueValues[nameValue] = [newID] row[1] = newID updateRows.updateRow(row) del row, updateRows uniqueCount = {} for val in uniqueValues: uniqueCount[val] = values.count(val) with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME", "FREQ"]) as updateRows: for row in updateRows: nameValue = row[0] row[1] = uniqueCount[nameValue] updateRows.updateRow(row) del row, updateRows
If you really want to do it all in python, as a first step, add a field called 'FREQ' to the table. Then run this modified version of the above code:import arcpy from arcpy import env env.workspace = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" table = "WAYNE" uniqueValues = {} values = [] newID = 1 with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows: for row in updateRows: nameValue = row[0] values.append(nameValue) if nameValue in uniqueVals: row[1] = uniqueValues[[nameValue]] else: newID += 1 uniqueValues[nameValue] = [newID] row[1] = newID updateRows.updateRow(row) del row, updateRows uniqueCount = {} for val in uniqueValues: uniqueCount[val] = values.count(val) with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME", "FREQ"]) as updateRows: for row in updateRows: nameValue = row[0] row[1] = uniqueCount[nameValue] updateRows.updateRow(row) del row, updateRows
The arcpy.da.UpdateCursor is definitely faster than the field calculator tool, at least in my testing (if you were going to summarize -> join -> calculatefield -> remove join), can't say that they will be than the summary stats alone.
import arcpy from arcpy import env env.workspace = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" table = "WAYNE" uniqueValues = {} values = [] newID = 1 with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows: for row in updateRows: nameValue = row[0] values.append(nameValue) if nameValue in uniqueVals: row[1] = uniqueValues[[nameValue]] else: newID += 1 uniqueValues[nameValue] = [newID] row[1] = newID updateRows.updateRow(row) del row, updateRows uniqueCount = {} for val in uniqueValues: uniqueCount[val] = values.count(val) with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME", "FREQ"]) as updateRows: for row in updateRows: nameValue = row[0] row[1] = uniqueCount[nameValue] updateRows.updateRow(row) del row, updateRows