1

I'm trying to join a layer with an Excel CSV utilizing the first 6 digits of the column called "concated" and "BBL". but I get the following error:

Runtime error Traceback (most recent call last): File "", line 16, in File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\management.py", line 7554, in MakeTableView raise e ExecuteError: ERROR 999998: Unexpected Error.

import arcpy
    
    # Define input CSV file and feature layer
    csv_file = r""
    layer = r""
    
    # Define field names for join
    csv_field = "Concated"
    layer_field = "BBL"
    
    # Delete existing csv_layer view if it exists
    #if arcpy.Exists("csv_layer"):
    #    arcpy.Delete_management("csv_layer")
    
    # Create feature layers for both the CSV file and the layer
    csv_layer = arcpy.MakeTableView_management(csv_file, "csv_layer")
    layer_feature = arcpy.MakeFeatureLayer_management(layer, "layer_feature")
    
    # Extract the first six digits of the "Concated" field in the CSV file
    arcpy.AddField_management(csv_layer, "First6Digits", "LONG")
    arcpy.CalculateField_management(csv_layer, "First6Digits", "int(!Concated![:6])", "PYTHON_9.3")
    
    # Join the two feature layers based on the extracted digits and the "BBL" field in the layer
    arcpy.AddJoin_management(layer_feature, layer_field, csv_layer, "First6Digits", "KEEP_COMMON")
    
    # Copy the joined layer to a new feature class
    joined_fc = r""
    arcpy.CopyFeatures_management(layer_feature, joined_fc)

1 Answer 1

0

You do not define the path to your CSV file or layer, you have set them to be empty strings, so that is why the make table view tool fails as your input is nothing. csv_file should be some thing like csv_file =r"c:\temp\mydata.csv". But your code is flawed further on. A CSV file is read only to ArcMap and you attempt to add a field to it. If you need to do that you need to convert your CSV to a proper table that supports proper table functions. You need to read and understand this page.

Your Answer

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

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