Select to view content in your preferred language

Problem with Summary Statistics in ArcPy

1886
6
06-27-2013 09:09 AM
mauriziogibin
Emerging Contributor
Hello,
I have a question regarding Summary Statistics in ArcPy.
I am working with a feature class that contains points whose attributes are two string fields called "CATEGORY" and "NAME".
I would like to count the number of points by category.
I believe the summary statistics is very useful in this case.
So the syntax would be:

arcpy.Statistics_analysis(<points>, <points_dbf>, [["CATEGORY", "COUNT"]], "CATEGORY")

NOTE: the <> are used to simplify the input and output table of course! I did not code it like that! 🙂

When I run it as a stand alone script I got a message saying that the ,<points_dbf> cannot be created. It is actually created but it is empty.
I think the mistake can be in the way I am passing the fields and statistics required AND I also have a rather sinister feeling...
Do the fields HAVE to be numeric?
I am sure and tested in both ModelBuilder and Python Window they do not have to be numeric.
Any help appreciated!
Tags (2)
0 Kudos
6 Replies
RhettZufelt
MVP Notable Contributor
This seems to work:


import arcpy


InPoint = "\\\\hgis01\\gishome\\ladietz\\WCH.gdb\\MR\\MRPoint"
out_dbf = "D:\\temp\\test.dbf"

arcpy.Statistics_analysis(InPoint, out_dbf, "CATEGORY COUNT;OSE_ID NAME", "")






R_
0 Kudos
MathewCoyle
Honored Contributor
It requires a numeric field.

Edit: Nevermind, it seems the help is outdated. You can count non-numeric fields.
0 Kudos
mauriziogibin
Emerging Contributor
This seems to work:


import arcpy


InPoint = "\\\\hgis01\\gishome\\ladietz\\WCH.gdb\\MR\\MRPoint"
out_dbf = "D:\\temp\\test.dbf"

arcpy.Statistics_analysis(InPoint, out_dbf, "CATEGORY COUNT;OSE_ID NAME", "")






R_


I found what is the problem! Thanks for your help...
It seems to have a problem when I triy to write the dbf table inside a gdb.
I tested the script and when you write in the different location, everything works fine. If you try to write on a gdb - the same where the input feature class is - you get an error saying the table cannot be created...The probme is solved but I would like to know why this happens and of course I would like to write the table in the same gdb where the in put feature class is.
Thanks for your help and....any ideas???
0 Kudos
MathewCoyle
Honored Contributor
I found what is the problem! Thanks for your help...
It seems to have a problem when I triy to write the dbf table inside a gdb.
I tested the script and when you write in the different location, everything works fine. If you try to write on a gdb - the same where the input feature class is - you get an error saying the table cannot be created...The probme is solved but I would like to know why this happens and of course I would like to write the table in the same gdb where the in put feature class is.
Thanks for your help and....any ideas???


You cannot write a dbf to a gdb... you would have to create a gdb table.
0 Kudos
RhettZufelt
MVP Notable Contributor
It uses the file extention to determine what type of table/file you are trying to create. 

If you are trying to write the dbf inside a FGDB, then you are most the way there.  Just drop the .dbf extension from the filename and it will create a FGDB table instead and will let you save it there.

R_
0 Kudos
mauriziogibin
Emerging Contributor
You cannot write a dbf to a gdb... you would have to create a gdb table.


Thank you very much!
Now the problem is solved!
Thanks a lot for your help!

Maurizio
0 Kudos