I am trying to join a csv-attribute table to a shapefile based on a variable ("pct16").

This is my code:

path_shp = cd + "ArcGIS/"
path_data = cd + "data/2016/raw/"
arcpy.JoinField_management(path_shp + "voting_precincts.shp", "pct16", path_data + "all_precinct_results.csv", "pct16")

When I run it, I get the following error:

ERROR 000339: Input C:/.../raw/all_precinct_results.csv does not have OIDs

The ESRI help advices to add an OID column to the table. My question is, how do I do that in ArcPy? Or, are there any quicker alternatives for my purpose?

A question that seems to be related is Working around Table does not contain OIDs arcpy Error 000339?. Maybe, it contains useful information to solve my problem but I was not able to judge for myself because I did not understand the question.


You need to use the Copy Rows arcpy function (same tool you'd use in ArcToolbox) and turn your csv into a table (with OIDs) before joining. Give this a shot:

path_shp = cd + "ArcGIS/"
path_data = cd + "data/2016/raw/"

arcpy.CopyRows_management("Test.csv", "all_precinct_results")    
arcpy.JoinField_management(path_shp + "voting_precincts.shp", "pct16", path_data + "all_precinct_results", "pct16")

After you run this code, take a look inside your folder in ArcCatalog, refresh the view, and see that the new table with OIDs has been created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.