Why does the code below come up with different field data names?

When I save in a GDB it comes up with underscore() on the end of the field name & when saved as .shp it comes up with no underscore().

import arcpy

# Envrionmental variable 
arcpy.env.workspace = arcpy.GetParameterAsText(0)
arcpy.env.overwriteOutput = True

# Variables
in_StatisticsTable = arcpy.GetParameterAsText(1)
in_ExcelFile = arcpy.GetParameterAsText(2)
Field = arcpy.GetParameterAsText(3)
in_BufferFeatures = arcpy.GetParameterAsText(4)
BufferDistance = arcpy.GetParameterAsText(5)
out_Feature = arcpy.GetParameterAsText(6)

# Summary Statistic
   out_StatisticsTable = arcpy.env.workspace + "\out_SummaryStatistics.dbf"
   StatsFields = [["Area", "SUM"]]
   arcpy.Statistics_analysis (in_StatisticsTable, out_StatisticsTable, StatsFields, "Brgy")

# Excel to Table
   out_Table = arcpy.env.workspace + "\Out_ExcelToTable.dbf"
   arcpy.ExcelToTable_conversion (in_ExcelFile, out_Table)

# Join Field
   in_JoinField = out_StatisticsTable
   joinTable = out_Table
   JoinField = ["Brgy", "ADD"]
   arcpy.JoinField_management (in_JoinField, Field,  joinTable, Field, JoinField)

# Join Field
   in_JoinField = in_StatisticsTable
   joinTable = out_StatisticsTable
   arcpy.JoinField_management (in_JoinField, Field,  joinTable, Field)

# Feature to Point
   in_HouseHoldFile = in_StatisticsTable
   out_FeatureToPoint = arcpy.env.workspace + "\out_FeatureToPoint.shp"
   arcpy.FeatureToPoint_management (in_HouseHoldFile, out_FeatureToPoint)

# Buffer
   outfeatureclass_Buffer = arcpy.env.workspace + "\out_Buffer.shp"
   arcpy.Buffer_analysis (in_BufferFeatures, outfeatureclass_Buffer, BufferDistance, "FULL", "ROUND")

# Intersect
   in_Intersect = [out_FeatureToPoint, outfeatureclass_Buffer]
   outfeatureclass_Intersect = out_Feature
   arcpy.Intersect_analysis (in_Intersect, outfeatureclass_Intersect, "ALL", "", "INPUT")

Most probably you are using a reserved word for file geodatabase (https://support.esri.com/en/technical-article/000010906), explained as:

Using a reserved word as a column name will return an error indicating that the column name is invalid. Copy/Paste from a data source where the word is not reserved will add a "_" to the end of any table or column name that is reserved within the file geodatabase

  • Thanks a lot! :)
    – choc
    Feb 6 '20 at 8:46

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.