[GIS] How to merge dbf files(zonal statistics as a table) in GIS environment.

arcgis-desktoparcpydbfpython

enter image description here
I am not very savvy at using Python. Actually I have around 1000 output files from using the tool zonal statistics as table in ArcGIS. The names of the files are jan_60, feb_60……dec_13. These all lie in one folder. Each of these files contain an ID and Name field which are my identifiers. And each file has got a column of interest called Mean. So what I want is that all the files be merged, using ID and name field. In the final table, I want one column added having the mean values from each of the individual tables. Note that I want the name of the new columns as the original file name. I am trying to give you a visualization below:

original files I have:

ID Name Mean

output file needed:

ID Name jan_60 feb_60 march_60

Can someone help me out, if any of you have had a similar task. It would be great if I can have a script or something.
Thanks a lot.

output file needed
output file needed
folder containing individual files

folder containing individual files
one of the individual

one of the individual

Best Answer

So the file names would then be fields in the output table? Seems like you would need to add a field to each table (let's call it "FILE_NAME"), merge all the tables together, then use the ArcGIS PivotTable tool (pivot on the FILE_NAME field). If you have 1000 tables, would you then have 1000+ fields? Not sure if this would be the best table structure...

Code to add file names to tables would look something like this (untested) code:

arcpy.env.workspace = r"C:\my_dir"
tableList = arcpy.ListTables()
for table in tableList:
    arcpy.AddField_managment(table, "FILE_NAME", "TEXT", "", "", "100")
    arcpy.CalculateField_managment(table, "FILE_NAME", "'" + table + "'", "PYTHON")