AnsweredAssumed Answered

How to specify fields to use in a merge?

Question asked by jbridwell_Dewberry on Oct 30, 2019
Latest reply on Oct 31, 2019 by nahmed-esristaff

I am using arcpy to merge multiple feature classes from a list of feature classes. They all have the same fields. Let's say they all have the fields = ['CO_FIPS', 'MILES', 'FLOOD_ZONE', 'VALID', 'REGION']. However, I only want to include 'CO_FIPS', 'MILES', and 'FLOOD_ZONE' in the output merged feature class. It seems I need to use field mapping to limit the fields in my output, but I am not 100% how to do that:

working_dir = r"C:\Projects\MyProj\stream_lines.gdb"
arcpy.env.workspace = working_dir
= ['stream1', 'stream2', 'stream3']
fieldMappings = arcpy.FieldMappings()
merged_output = os.path.join(working_dir, "AllStreams")
for field in fieldMappings.fields: 
    if not in ['CO_FIPS', 'MILES', 'FLOOD_ZONE']:  
.Merge_management(s_studies_for_merge, merged_output, fieldMappings)

My confusion is mainly that most examples show only 2 features being merged and that the mapping involves settings that I don't need for certain fields. I only want to exclude the fields I don't want and keep the fields I do. What do I need to do here?