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.
- In ArcGIS Pro, click the Insert tab > New Notebook (in the Project section of the ribbon)
- Your first cell should read
import arcgis, pandas
- 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")
- DataFrame/Series filters are outside the scope of this post, but you can create one with syntax like this:
dfFiltered = df[df["STATUS"] == "CLOSED"]
- Obtain a statistics table with a line like this:
dfStats = dfFiltered.groupby(by=["Field1", "Field2"])
- 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.