List Unique Values in Multiple Columns

02-15-2022 08:53 AM
Labels (2)
Occasional Contributor II

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()


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

Hope you can use ArcGIS Pro for your processing.

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:



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”:


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

0 Kudos