*EDIT*
I realized after posting this question that the code didn't quite come through as formatted as I remember the last time I posted something. Has the formatting changed, or did I do something wrong? Thanks!
Hello,
I have a script that I am using to iterate through a list of all fields in a feature class, run summary statistics on itself to get a table of all entries, and then creates a file geodatabase copy as well as an excel copy of the table. The tool that I have is working seemingly well, but I end up getting an error at the end.
The code:
import arcpy
from arcpy import env
import datetime
generalFeatures = r'OSP Mapping Layers\General Features'
dateToday = datetime.date.today()
outPath = r'"local_shared_drive"
generalVar = "general"
datedFolder = str(dateToday)
arcpy.CreateFolder_management(outPath, datedFolder)
outGDB = str(dateToday) + ".gdb"
arcpy.CreateFileGDB_management(datedFolder, outGDB, 'CURRENT')
inFC = generalFeatures
fields = [f.name for f in arcpy.ListFields(inFC)]
fieldCount = len(fields)
i = 0
for f in fields:
while i < fieldCount:
i += 1
fieldVar = fields[i]
statsFields = [[fieldVar,"COUNT"]]
caseFields = [fieldVar]
outTable = generalVar + "_" + fieldVar
arcpy.Statistics_analysis(inFC, outTable, statsFields, caseFields)
inTable = inFC
saveGDB = outPath + str(dateToday) + "/" + outGDB
arcpy.TableToTable_conversion(inTable, saveGDB, outTable, "", "", "")
arcpy.AddMessage("Summary table created for the " + fieldVar + " field!")
inTable = outTable
outXLS = outPath + str(dateToday) + "/" + generalVar + "_" + fieldVar + ".xls"
arcpy.TableToExcel_conversion(inTable, outXLS)
arcpy.AddMessage("Excel sheet created for the " + fieldVar + " field!")
print("General Features summary tables have been created for all fields!")
This script runs through and does exactly what it is meant to do for each field, but then I get this error:
I have 4 other feature classes that I would like to eventually add onto this script to run through the exact same process for each of the feature classes, but I can't get it to work on the second feature class with this error getting triggered after the first feature class wraps up. Any ideas why it is giving me a field type error even though the tool has technically already exported out each of the fields to tables?
*SIDE NOTE* (let's fix the problem above first)
The tool needs another minor tweak as well in the fact that in its current state, it creates a copy of the table in my default database before it creates a copy in my created database via the table to table function, which obviously poses the problem of having pre-existing tables when running subsequent times after the first. I had to try various workarounds when trying to get this to work initially. For instance, whenever I have an env.workspace declared under the initial while loop's local variables, I would later get an error stating that the table already existed when I tried the table to table function. However, if I removed the table to table function and relied on the env.workspace table created down in the table to excel function, I would get an error saying that the table couldn't be read.