Select to view content in your preferred language

List Unique Values in Multiple Columns

1754
2
02-15-2022 08:53 AM
Labels (2)
RogerDunnGIS
Frequent Contributor

When getting to know a feature class, or analyzing one I'm familiar with, the Frequency tool is helpful.  But if I'm not mistaken, Frequency is not available at all levels of ArcGIS Desktop.  Also, the Frequency tool always outputs a persisted table, and I don't always want that.  Here is how to generate a Pandas object consisting of unique combinations of values in multiple fields, along with counts of how frequently those combinations appear.  This code is mostly useful for text/string fields.  Other pandas properties are good for numeric fields, which is outside the scope of this post.

  1. In ArcGIS Pro, click the Insert tab > New Notebook (in the Project section of the ribbon)
  2. Your first cell should read

 

import arcgis, pandas​

 

  1. Your second cell should read something like this, but the word in quotes should be the name of a layer in your map.  If you have records selected in this layer, then the DataFrame df will only contain those records.

 

df = pandas.DataFrame.spatial.from_featureclass("Sidewalk Repair Inventory")

 

  1. DataFrame/Series filters are outside the scope of this post, but you can create one with syntax like this:

 

dfFiltered = df[df["STATUS"] == "CLOSED"]

 

  1. Obtain a statistics table with a line like this:

 

dfStats = dfFiltered.groupby(by=["Field1", "Field2"])

 

    1. Lastly, you need a few short lines like this:
result = dfFrequency.size()
print(result)

 

Sorry the formatting of this post is odd.  I couldn't fix it.  I don't know how, in this forum, to post an ordered list of steps while continuing the order below the code segments.

 

0 Kudos
2 Replies
DanLee
by Esri Regular Contributor
Esri Regular Contributor

I am not sure which product you are using, ArcGIS Desktop (ArcMap) or ArcGIS Pro, as you mentioned both.  If you are using ArcGIS Pro, I would like to mention two things for you:

1. Frequency is available at Basic licensing level.

2. Summary Statistics has an option:

  • UNIQUE—The number of unique values of the specified field will be counted.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/summary-statistics.htm

Hope you can use ArcGIS Pro for your processing.

ChristopherAllen
Esri Contributor

I wanted to add that charts are another effective way of exploring your data in ArcGIS Pro. Bar charts can help you quickly visualize the frequency distributions for categorical fields without needing to create an extra output table.

Here I’ve created a bar chart that shows the counts for AirBNB listings by the “neighbourhood_group” field:

callen_esri_2-1645227738440.png

 

You can even group the data by an additional categorical field by selecting the field in the Split by dropdown. Here I’ve split the chart above by the “room_type” field, and now it displays the breakdown of AirBNB listings by “neighbourhood_group” and “room_type”:

callen_esri_1-1645225966216.png

For more information on creating and configuring charts in ArcGIS Pro, please see the following documentation page:

https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/charts/charts-quick-tour.htm

0 Kudos