3

I am trying to join a shapefile and a CSV file. I have tried Arcpy.AddJoin_management... the error message I receive is that there is no field name for the CSV file.

I tried to index it and same error message shows up.

import arcpy
from arcpy import env
env.workspace = "E:\county" 
in_data = "county.shp"
out_data = "E:\county\County2.shp"
data_type = ""
arcpy.Copy_management(in_data, out_data, data_type) 
arcpy.env.overwriteOutput = True 
arcpy.MakeFeatureLayer_management ("E:\\county\\County2.shp")
arcpy.MakeTableView_management ("E:\county\data.csv")
LayerName = "County_Layer" 
Field = "NAME"
TableName = "data_View"
Field2 = "County"
arcpy.AddJoin_management (LayerName, Field, TableName, Field2)
Traceback (most recent call last):
 File "<pyshell#15>", line 1, in <module>
 arcpy.AddJoin_management (LayerName, Field, TableName, Field2)
 File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\management.py", line 6066, in AddJoin
 raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000728: Field County does not exist within table
Failed to execute (AddJoin).

enter image description here

enter image description here

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Apr 13, 2017 at 15:59
10
  • 1
    show us your code Commented Apr 13, 2017 at 16:01
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. A question asking for help with code should include a snippet of the code you have tried, and details about what happens when you try it and where you are stuck. Please edit your question to include your code snippet and any other relevant information. Commented Apr 13, 2017 at 16:03
  • A sample/screenshot of your csv and details of your shapefile would be useful also. Commented Apr 13, 2017 at 16:03
  • Please also edit your question to include your error message in full including all line numbers mentioned Commented Apr 13, 2017 at 16:25
  • 1
    You might try working through the table of contents to perform the join. Add the csv to the project and use the join tool. Commented Apr 13, 2017 at 17:10

1 Answer 1

3

The path you use in your MakeTableView statement is incorrect. Python will not interpret the single backslash in your path string correctly. You can use any of these to represent a file path string:

  • r"E:\county\data.csv"
  • "E:\\county\\data.csv"
  • "E:/county/data.csv"
answered Apr 13, 2017 at 16:51
2
  • Thanks for catching that. After correcting it, the same error message still shows up. Commented Apr 13, 2017 at 17:04
  • Just noticed the same problem on lines 4 & 7. Please edit the code in your original post as you correct them. Commented Apr 13, 2017 at 17:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.