Use the results of arcpy.Statistics_analysis

1241
2
Jump to solution
02-08-2014 12:33 AM
NeoGeo
by
Occasional Contributor III
Is there a tool like summary statistics or arcpy.Statistics_analysis that returns some type of usable object so you can use the results for further processing instead of getting a dbase table stored to disk, or is standard procedure to create your own by iterating through every row and calculating that way?

Thanks!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
Is there a tool like summary statistics or arcpy.Statistics_analysis that returns some type of usable object so you can use the results for further processing instead of getting a dbase table stored to disk, or is standard procedure to create your own by iterating through every row and calculating that way?

Thanks!


I don't know what kind of additional processing you are thinking you want to do or why you object to creating a separate output to disk or inmemory.  However, Summary Statistics will always return a separate table of summary results, whether dbase table, geodatabase table, or inmemory table that is not connected to the original data.  You then use a layer/table view of the original data with a join to the summary output (assuming the summary uses a single field for the unique case argument) and use the field calculator to alter the original table based on the summary.

The only way I know of to do this without creating a separate table to disk or inmemory with a geoprocessing tool is to use a cursor twice on the original data.  The first read cursor reads the data and stores the summary in a dictionary (effectively creating an inmemory table like Summary Statistics can do), with the key being the unique case field(s) and the type of summary you want (a tuple value if multiple summaries are done) for the value and then process a second update cursor against the original data and extract the dictionary summary values using the case field value key you set up to act on some field in the original data.

Either method works to create the same result, but the summaries always first have to be extracted from the original data and stored in some kind of table or dictionary prior to altering the original data based on the summaries.  I do the first method more than the second, since the first method can easily be set up in ModelBuilder.  You should only consider the second method if you are at 10.1 or above and can use the arcpy da cursors, which are many times faster than the prior version of python cursors.

View solution in original post

0 Kudos
2 Replies
RichardFairhurst
MVP Honored Contributor
Is there a tool like summary statistics or arcpy.Statistics_analysis that returns some type of usable object so you can use the results for further processing instead of getting a dbase table stored to disk, or is standard procedure to create your own by iterating through every row and calculating that way?

Thanks!


I don't know what kind of additional processing you are thinking you want to do or why you object to creating a separate output to disk or inmemory.  However, Summary Statistics will always return a separate table of summary results, whether dbase table, geodatabase table, or inmemory table that is not connected to the original data.  You then use a layer/table view of the original data with a join to the summary output (assuming the summary uses a single field for the unique case argument) and use the field calculator to alter the original table based on the summary.

The only way I know of to do this without creating a separate table to disk or inmemory with a geoprocessing tool is to use a cursor twice on the original data.  The first read cursor reads the data and stores the summary in a dictionary (effectively creating an inmemory table like Summary Statistics can do), with the key being the unique case field(s) and the type of summary you want (a tuple value if multiple summaries are done) for the value and then process a second update cursor against the original data and extract the dictionary summary values using the case field value key you set up to act on some field in the original data.

Either method works to create the same result, but the summaries always first have to be extracted from the original data and stored in some kind of table or dictionary prior to altering the original data based on the summaries.  I do the first method more than the second, since the first method can easily be set up in ModelBuilder.  You should only consider the second method if you are at 10.1 or above and can use the arcpy da cursors, which are many times faster than the prior version of python cursors.
0 Kudos
NeoGeo
by
Occasional Contributor III
I knew there had to be some simple answer to this question which I just was not seeing.  I gave you the point because the answer was simply doing a table join.  At this point I have already written a script using cursors and creating the statistics on the fly, but I appreciate the answer because that is something that has perplexed me for a long time.
0 Kudos