OID field included in table export (and shouldn't be)

2663
8
Jump to solution
11-30-2021 02:05 PM
TychoGranville
Occasional Contributor II

Using Table to Table to export to a csv file adds the OID field even though it is not included in the model. It does the same thing when running it as a python script as well.

Model popup: (no OID field listed)

Capture2.PNG

Python snippet: (no OID field listed before the first field)

Spoiler
# Process: Table To Table (Table To Table) (conversion)
with arcpy.EnvManager(qualifiedFieldNames=False):
GIS_Export_csv = arcpy.conversion.TableToTable(in_rows=GISVotersJune2021_2_, out_path=Redistricting2021, out_name="GIS_Export.csv", where_clause="", field_mapping="RESADR_ID \"RESADR_ID\" true true false 255 Text 0 0,First,#,GISVotersJune2021,Text$.RESADR_ID,0,255;IS_STANDARD....<snip>

Output csv with extra field:

Spoiler
OID_,RESADR_ID,IS_STANDARD,ADDR_NON_STD,HOUSE_NUM,HOUSE_SUFFIX,PRE_DIRECTION,STREET_NAME,STREET_TYPE,POST_DIRECTION,UNIT_TYPE,UNIT_NUM,CITY,STATE,ZIP_CODE,ZIP_PLUS,SPL_ID,PRECINCT,

How do I get rid of it? Right now I'm dumping the table into Excel (and not importing that field) which is a pain.

Thanks,

Tycho

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

This sort of thing isn't specific to Pro, but when dealing with tabular datasets, the program adds an OID field to most outputs that don't have a built-in ID method like ObjectID / GlobalID.

I'm sure there's a good arcpy option, but when I'm exporting to text files, I like to use pandas to_csv, via the ArcGIS Python API. It may not be compatible with your larger script / model, but here's an example.

from arcgis.features import GeoAccessor

fl = GeoAccessor.from_featureclass('path/to/featureclass')

fl.to_csv('./output.csv', index=False)

By specifying index=False, no index is included in the output.

- Josh Carlson
Kendall County GIS

View solution in original post

8 Replies
jcarlson
MVP Esteemed Contributor

This sort of thing isn't specific to Pro, but when dealing with tabular datasets, the program adds an OID field to most outputs that don't have a built-in ID method like ObjectID / GlobalID.

I'm sure there's a good arcpy option, but when I'm exporting to text files, I like to use pandas to_csv, via the ArcGIS Python API. It may not be compatible with your larger script / model, but here's an example.

from arcgis.features import GeoAccessor

fl = GeoAccessor.from_featureclass('path/to/featureclass')

fl.to_csv('./output.csv', index=False)

By specifying index=False, no index is included in the output.

- Josh Carlson
Kendall County GIS
GlenOlliEsriUK
New Contributor II

Hey Josh,

What about removing the OID field from a Table to Table export as a csv file.

I have created a python script from a Model Builder and apparently when I run it it creates me a csv file and the OID header is there although with no data. There is no OID in the fields of the Table that I am using to export.

0 Kudos
TychoGranville
Occasional Contributor II

Thanks, Josh. Guess it's time to actually learn python instead of mostly stealing other peoples scripts 🙂

0 Kudos
ChelseyAiton2
New Contributor III

Were you able to come up with a solution that tied into your model, or did Josh's pandas to csv suggestion work for you? I am loading tab delaminated text files into another program and have also been using Excel to remove the OID but would like to include this in my model. Based upon your field names, I believe we are both working with the same program.

 

Thanks,

Chelsey  

0 Kudos
TychoGranville
Occasional Contributor II

Sorry about the delay, this got lost in the holiday madness... I ran out of time (at least as much as I was willing to spend) to get pandas/notebook to work so mostly brute-forced it. In sum:

Import the original tab-delimited file to Excel (using data model/data refresh so I wasn't manually fixing the fields each time)

Do the work on my FC

Join the Excel table to my FC

Made a simple table-to-table model to rearrange/change field names so only the updated/required fields exported

Imported the csv back into Excel (since Pro can't directly export tab-delimited through models- not sure if 2.9 added that)

Exported from Excel to a tab-delimited file

Dumped it back into the Clerk's software.

I had to run the Clerk's data a bunch of times so even this semi-automation saved me some time.

Thanks,

Tycho

0 Kudos
ChelseyAiton2
New Contributor III

I also gave up scripting this part and partially automated the rest of the steps, which are very similar to yours as I am also working on redistricting in Oregon. Though I went straight from the OCVR text file to a geodatabase table using Table To Table and a schema.ini file to handle the field data types. The Table to Table tool responds to the data types designated in this file. My version of Pro is 2.9 and I am able to export a tab-delaminated file in my model. Just have to include .tab in the output file name. I still have to change that file to a .txt file and load it into Excel to remove the OID. 

I tried to respond to your gis_info_request email directly but it was undelivered. If you would like to communicate directly my email is caiton@co.marion.or.us

 

Thanks,

 

Chelsey

 

0 Kudos
TychoGranville
Occasional Contributor II

My County Clerk hit commit last Friday afternoon so I am (so) done with this project (until 2030 at any rate...).

Tycho

(tychog@co.wasco.or.us)

ChelseyAiton2
New Contributor III

I can appreciate that! I am not far behind you.

0 Kudos