I have a Census dataset that contains eight fields with percentages. I would like a python script that finds the highest value between the eight fields, but also tells me which field the highest value came from. I've gotten halfway there using Field Calculator in ArcMap 10.3, using the max(!field1!, !field2!, !field3!) script.
However, I also need it to be able to somehow add the field name because ultimately, the field name is what I want in a new indivisual field, and I will symbolize based on that field.
So far, my programmer colleague helped me come up with the following python script but I am getting an error message regarding my gp and not too python savvy to get it working.
import arcpy fc = "C:/filename" #or shapefile address gp = arcgisscripting.create() # Create update cursor for feature class. rows = gp.UpdateCursor(table) row = rows.Next() field_list = ["ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT"] while row: highname_values = [row.GetValue(f) for f in field_list] zipped = zip(eth_values, field_list) zipped.sort(key=lambda t: t, reverse=True) row.highname = zipped # replace ETH for the field that you want to update with the field name (ONE, TWO, ETC) row.HIGH = zipped rows.UpdateRow(row) # Go to the next row = rows.Next()