0

I was about to take input from an excel and using conversion tool in arcpy I have to convert the excel to table in a gdb. But when I used this Excel to table tool, I found that there are columns named 'F34', 'F35' etc which in excel does not hold anything.

How do I either remove those columns from the table or avoid those columns while doing conversions?

closed as off-topic by PolyGeo Apr 29 at 10:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    If you only select the columns you want and copy paste into a new blank excel i think the empty columns will disappear. – BERA Apr 29 at 9:16
2

You can use the field_info parameter of Make Table View to set the fields as HIDDEN. But it is easier to drop them after import:

import arcpy
table = r'C:\data.gdb\sometable'

fields_to_drop = ['F35','F36']
#or
fields_to_drop = [f.name for f in arcpy.ListFields(table) if f.name.startswith('F3')]
#or
fields_to_drop = [f.name for f in arcpy.ListFields(table) if len(f.name)<4 and not f.required]
#or something else

arcpy.DeleteField_management(in_table=table, drop_field=fields_to_drop)
  • Hello Bera Thanks for sharing it. I understand what you have described. But only one thing I am not getting is the hard coding part. In case if you have something to remove the hard coding. I mean in future I may get some blank columns which may not be F35 or F36. – royan Apr 29 at 12:19
  • You did not include this information in your original question. You would have to iterate over all values in each column and check if they are empty – BERA Apr 29 at 12:22

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