unique table values in arcgis

9060
16
08-23-2014 08:30 AM
LukeNewman
New Contributor

Hi, I was wondering if there was a way to obtain unique field values for an attribute table for ModelBuilder in ArcMap 10.1. I haven't got a license for a Frequency Analysis. Thanks.

0 Kudos
16 Replies
JamesCrandall
MVP Frequent Contributor

Assuming you are talking about a GDB table, this is an alternative using pandas library (this spits out a .csv table but it could also be run thru a TableToTable conversion just as well to keep it all withing the gdb).  "fc" is a string field and the output adds a count field.


import arcpy


import pandas as pd





def createSummaryGDB(ingdb):
    tab = ingdb + "\\arlist"
    flds = [f.name for f in arcpy.ListFields(tab)]
    tabarray = arcpy.da.TableToNumPyArray(tab, flds)
    df = pd.DataFrame(tabarray)
    df_grouped = df.groupby(['fc']).count()
    df_grouped.to_csv(r'H:\Documents\arlist_grouped.csv')





createSummaryGDB(r'H:\Documents\ArcGIS\Default.gdb')

0 Kudos
curtvprice
MVP Esteemed Contributor

James, please visit this thread and tell us how you got Pandas to work. Other people have had trouble:

Cannot import pandas - ArcGIS 10.1

0 Kudos
JamesCrandall
MVP Frequent Contributor

Hi Curtis --- I did post over in that thread!  Unfortunately, I am not privy to installs and such -- juts a Citrix account with what they give me to work with is all I have and really can't contribute much to help in that thread.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Field Statistics does work in 10.2.2 should you still need to use the code

0 Kudos
curtvprice
MVP Esteemed Contributor

Luke, it would be helpful if you gave us a use-case. What are you doing with the unique list once you have it? For example, if you simply want to process your data in groups the Iterate Field Values tool is the ticket.

0 Kudos
LukeNewman
New Contributor

Forgive me, I am quite new to python so this may be pretty basic to you guys. Basically I have an attribute table of a shapefile in ArcGIS which contains a list of points of interest in London. One of the columns is named 'category' and there is a list of this types of points of interest such as 'automotive', 'tourism' and 'eating/drinking'. What I need to do is create a code in python which creates a new table as a '.dbf' file which displays a tally of the number of points of interest for each category - something which would look like this:

Automotive - 326

Tourism - 56

Eating / Drinking - 126

I have realised that I don't actually need to display this process in ModelBuilder, I just need to write the code for it. Thanks for your help guys, I will try the Field Statistics code but if anyone else has some starter code which you think might be helpful then please share! Regards

0 Kudos
RichardFairhurst
MVP Honored Contributor

Luke:

The table you want could have been produced 4 days ago if you would just have used the Summary Statistics tool.  The "category" field would be the input to the case_field parameter.  A frequency field will automatically be generated that gives the counts you want, so you don't really need a summary to get the output you want, but the tool requires at least one summary parameter input.  Since any field can be used for the summary, just use the "category" field and get its Count to duplicate the values in the Frequency field.

The output of the Summary Statistics tool will be a table that can be joined back to your original data for SQL selections and/or field calculations, or any of other uses that have been discussed so far.  Do not tell me that the tool cannot do what you want, because it definitely can.  As an example, here is the Summary Statistics tool output counting the codes that define my recorded map feature class categories:

OBJECTID *RECORDERS_TYPEFREQUENCYCOUNT_RECORDERS_TYPE
1MB1197711977
2PM1215912159
3RS41414141
4SB9696
5SD134134