Sunday 24 February 2019

arcgis desktop - An equivalent for field statistics for records



I know how to obtain various statistics for a field, or "column", in an attribute table in ArcGIS. Is there any way to obtain a Mode figure for records, or the "rows" in a table? For instance, an attribute table of plots of land might contain 15 fields each showing the number of a particular type of tree on each plot. I need to find out, for a particular plot, what type of tree is the most common there. What is the easiest way to find out which of the 15 fields has the highest figure for that record? Am I right that the answer somehow involves the Field Calculator?



Answer



you are right that you can use the field calculator, but you could also do this with a cursor. With the field calculator, you can define a function that take all your fields as input and gives the position of the field as an output.


argmax(!field1!,!field2!,!field3!,...,!field15!)


def argmax(a,b,c,...o):
mylist = [a,b,c,...o]
return mylist.index(max(mylist))


The same function can be used with a cursor, but then you have the advantage of being ble to list the fields automatically (listFields) and to get the name of the field instead of the number of the field.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...