Monday, 3 October 2016

arcgis 10.1 - How to count occurrences of one field grouped by values of another?


Is there a way of calculating the number of unique text strings in a field in ArcGIS 10.1? I have a number of repeated strings in this field, but would like to calculate the number of unique strings in a field based on groupings from another field.


E.g - Current table:



Field 1    Field 2   
Apple Green
Apple Red
Apple Red
Citrus Yellow
Citrus Green
Citrus Orange
Citrus Orange

Result:



Field 1    Field 2
Apple 2
Citrus 3

Answer



Two "summarize" operations will do it. This is a basic operation requiring no extra licenses.


First compute a field that concatenates Field1 and Field2. (If your table is not editable or should not be modified, do these operations on a copy of it.) It's a good idea to delimit the concatenation; here I have used "|" as a delimiter.


Field 1    Field 2    Concatenation
Apple Green Apple|Green
Apple Red Apple|Red
Apple Red Apple|Red

Citrus Yellow Citrus|Yellow
Citrus Green Citrus|Green
Citrus Orange Citrus|Orange
Citrus Orange Citrus|Orange

The summary of the Concatenation field, retaining the first occurrence of Field1, will look like


Concatenation  Field1  Count
Apple|Green Apple 1
Apple|Red Apple 2
Citrus|Yellow Citrus 1

Citrus|Green Citrus 1
Citrus|Orange Citrus 2

Finally, the summary of Field1 obtains what you want:


Field1 Count
Apple 2
Citrus 3

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...