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).
-
1show us your codeziggy– ziggy2017年04月13日 16:01:47 +00:00Commented 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.Midavalo– Midavalo ♦2017年04月13日 16:03:05 +00:00Commented Apr 13, 2017 at 16:03
-
A sample/screenshot of your csv and details of your shapefile would be useful also.Midavalo– Midavalo ♦2017年04月13日 16:03:37 +00:00Commented Apr 13, 2017 at 16:03
-
Please also edit your question to include your error message in full including all line numbers mentionedMidavalo– Midavalo ♦2017年04月13日 16:25:08 +00:00Commented Apr 13, 2017 at 16:25
-
1You might try working through the table of contents to perform the join. Add the csv to the project and use the join tool.SteveC– SteveC2017年04月13日 17:10:23 +00:00Commented Apr 13, 2017 at 17:10
1 Answer 1
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"
-
Thanks for catching that. After correcting it, the same error message still shows up.Lauryn– Lauryn2017年04月13日 17:04:28 +00:00Commented 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.Bjorn– Bjorn2017年04月13日 17:45:43 +00:00Commented Apr 13, 2017 at 17:45
Explore related questions
See similar questions with these tags.