Statistics_analysis fails

585
7
03-11-2011 04:49 AM
ChristopherJursa
New Contributor
Hello

I am trying to execute Statistics_analysis  from a python script.  However, it fails when I run it.  I exported this from a ModelBuilder from where it runs fine. 

import arcpy

# Local variables:
myShpFile = "C:\\temp\\stats\\forms\\outputDir\\0arbuckle\\intersect_1.shp"
stats_dbf = "C:\\temp\\stats\\waters\\stats.dbf"

# Process: Summary Statistics
arcpy.Statistics_analysis(myShpFile, stats_dbf, "field1 MIN;field1 MEAN;field1 MAX;field1 RANGE;field1 STD;field2 MIN;field2 MEAN;field2 MAX;field2 STD;field2 RANGE")



However, the execute python script gives me the following error.

Traceback (most recent call last):
  File "stats.py", line 19, in <module>

  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\analysis.py", line
910, in Statistics
    raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a String.
ERROR 000840: The value is not a String.
Failed to execute (Statistics).


What is wrong with my script?
Tags (2)
0 Kudos
7 Replies
ChrisMathers
Occasional Contributor III
Try running the tool outside of a model or script. Go to the results window and right click on the results and select "copy as python snippit." Paste this into IDLE or whatever and compare. Exports from model builder sometimes wonk out like this.
0 Kudos
ChristopherJursa
New Contributor
Try running the tool outside of a model or script. Go to the results window and right click on the results and select "copy as python snippit." Paste this into IDLE or whatever and compare. Exports from model builder sometimes wonk out like this.


What results window are you referring?
0 Kudos
ChrisMathers
Occasional Contributor III
In Map or Catalog, on the geoprocessing menu there is a results option. Clicking it will open up a new pane that has previously run tools in it.
0 Kudos
ChristopherJursa
New Contributor
To use this I apparently have to create a front end interface.

When I copy as Python snippet it only gives me the python interface call like arcpy.("", "").

It does not give me the python statistical invocation.
0 Kudos
ChrisMathers
Occasional Contributor III
I dont know why it isnt giving you the syntax when you do the snippit copy thing. Thats how many of us get complex syntax without having to type it all out by hand. I think one thing may be the way that model builder formatted your tool. It may have given you the syntax for 9.3.x instead of 10.x. Now the fields and stat type are strings in nested lists.
Try:
arcpy.Statistics_analysis(myShpFile, stats_dbf, [["field1","MIN"],["field1","MEAN"],["field1","MAX"],["field1","RANGE"],["field1","STD"],["field2","MIN"],["field2","MEAN"],["field2","MAX"],["field2","STD"],["field2","RANGE"]])
0 Kudos
ChristopherJursa
New Contributor
I dont know why it isnt giving you the syntax when you do the snippit copy thing. Thats how many of us get complex syntax without having to type it all out by hand. I think one thing may be the way that model builder formatted your tool. It may have given you the syntax for 9.3.x instead of 10.x. Now the fields and stat type are strings in nested lists.
Try:
arcpy.Statistics_analysis(myShpFile, stats_dbf, [["field1","MIN"],["field1","MEAN"],["field1","MAX"],["field1","RANGE"],["field1","STD"],["field2","MIN"],["field2","MEAN"],["field2","MAX"],["field2","STD"],["field2","RANGE"]])


You must have posted this right when I got the answer myself.  The help system had this syntax and it worked.  Thanks!

To do the code snippet procedure you mentioned, do I need to have an interaface on the tool or could I just build a mode without an interface?
0 Kudos
ChrisMathers
Occasional Contributor III
The code snippit would be for the stat tool specifically. Run Summary Statistics only and then copy its syntax.
0 Kudos