I am trying to write a script that recategorizes 70 attributes in to 1 of 5 attributes.
I have two tables, each with two columns that I am focusing on. The first table has one column with 20k rows that all contain 1 of the 70 strings.
The second table is the key used as a key. The first column has 70 rows, each listing one attribute type. The second column tells what that attribute converts in to. There are 5 options, so each of the 70 will fall in to one of those five.
What I need to script to do is read through the key one row at a time, then find all matching rows in the other table's column. For all of those matches, a second column in the original table needs to be populated with the corresponding attribute (from the 5 options).
I have trouble explaining this, but it is really just recategorizing 70 attributes into 5 attributes. These are all strings. The original table is a layer in ArcMap, and the key table is an excel file. I am not sure how to write this script.
Here is what I have so far:
import xlrd from xlrd import open_workbook xl_workbook = xlrd.open_workbook(conversion_table) xl_sheet = xl_workbook.sheet_by_index(0) num_cols = xl_sheet.ncols # Number of columns for row_idx in range(0, xl_sheet.nrows): # Iterate through rows print ('-'*40) print ('Row: %s' % row_idx) # Print row number for col_idx in range(0, num_cols): # Iterate through columns cell_obj = xl_sheet.cell(row_idx, col_idx) # Get cell object by row, col print ('Column: [%s] cell_obj: [%s]' % (col_idx, cell_obj)) # print water land use category column conversion_column = xl_sheet.col(0) list1 = list() list1.append(conversion_column) print list1 # print land use field from roadway fc = original_table field = "LAND_USE" cursor = arcpy.SearchCursor(fc) row = cursor.next() list2 = list() while row: results = (row.getValue(field)) list2.append(results) row = cursor.next() print list2
I'm using version 10.3.1.