I have a shapefile with an attribute table like this:
FID Shape ID
0 Polgyon 3
1 Polgyon 3
2 Polygon 3
3 Polygon 3
and numerous csv files which look something like this:
FID p-value t-stat
0 0.50 0.0004
1 0.01 0.0006
2 0.02 0.0007
3 0.04 0.0008
and I am joining the csv files to the shapefile and then exporting like this:
import arcpy, os
arcpy.CheckOutExtension('Spatial')
arcpy.env.workspace=r'H:\path_to_csv_files'
shapefile=r'H:\pathway_to_shapefile.shp'
out=r'H:\output_pathway'
#loop through csv files
for table in arcpy.ListTables("*"):
#Create a new feature layer, this will remove previous join
arcpy.MakeFeatureLayer_management(shapefile, "parcelLyr")
# Join table to feature layer
arcpy.AddJoin_management("parcelLyr", "FID", table, "FID", 'KEEP_COMMON')
tableName = table.split(".")[0]
if not os.path.isdir(out):
os.mkdir(out)
# #Export joined layer to new feature clas
arcpy.FeatureClassToFeatureClass_conversion("parcelLyr", out, tableName)
but my out put table looks like this:
FID Shape ID NDVI__5_cs NDVI__5__1
0 Polgyon 3 0.50 0.0004
1 Polgyon 3 0.01 0.0006
2 Polygon 3 0.02 0.0007
3 Polygon 3 0.04 0.0008
NDVI_5.csv
is the name of my first csv file so it is for some reason putting the name of the csv file as the column headers after the join. When I do the join manually in arcgis this doesn't happen though.