import os from operator import itemgetter import arcpy inspace = "C:/Data/export.gdb" shapefile = inspace + os.sep + "classification_2011_1028" fields = arcpy.ListFields(shapefile, "M*") # The "nonsense" name of the 10 fields all began with 'M' newfields = ["First", "Second", "Third"] # The empty fields where the top three numbers would go uCursor = arcpy.UpdateCursor(shapefile) for row in uCursor: fuzzy = [] topthree = [] x = 1 for field in fields: name = field.aliasName value = row.getValue(field.name) fuzzy.append([name,value]) fuzzy.sort(key=itemgetter(1),reverse=True) for f in fuzzy: if x < 4: topthree.append(f[0]) x+=1 for rank, value in zip(newfields,topthree): row.setValue(rank,value) uCursor.updateRow(row)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.