Create table from point feature class

453
5
05-13-2022 07:05 AM
ViennaCooper
New Contributor

Hello, 

I have want to create geodatabase table from geodatabase feature class. i have the following codes 

Occurances = []
with arcpy.da.SearchCursor (fc, field) as cursor:
for row in cursor:
Occurances.append (row[0])

for i in set(Occurances):
icount = Occurances.count(i)
print (str(i) + ":", icount)

but instead of printing i really want to create a table using python that shows item name and the number of times in appears in the the feature class. any help would be very much appreciated. thanks 

0 Kudos
5 Replies
curtvprice
MVP Esteemed Contributor

Either the Summary Statistics or Frequency tool would be easier and faster than doing this with a search cursor. Have you tried that?

0 Kudos
ViennaCooper
New Contributor

hello, yeah i tried that! i don't want to use any existing geoprocessing tools. i was wondering to how to do in python code without it. 

0 Kudos
curtvprice
MVP Esteemed Contributor

If you want to work with table data in Python, I recommend the arcpy method to copy tables to numpy arrays and using pandas. Right @DanPatterson_Retired ?

0 Kudos
DanPatterson
MVP Esteemed Contributor

TableToNumPyArray to get the array

python, numpy, scipy, etc,  magic analysis here....

NumPyArrayToTable to get the results back into Pro


... sort of retired...
0 Kudos
DonMorrison1
Occasional Contributor III

I think something like this would create and populate the table.

tbl = <path to table>
arcpy.management.CreateTable(os.path.dirname(tbl), os.path.basename(tbl))
arcpy.management.AddField(tbl, 'name', 'TEXT', field_length=255)
arcpy.management.AddField(tbl, 'count', 'LONG')
with arcpy.da.InsertCursor(tbl, ['name', 'count']) as cursor:
	for i in set(Occurances):
          	cursor.insertRow([str(i), Occurances.count(i)])

 

0 Kudos