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

129
4
Jump to solution
11-30-2021 02:05 PM
Labels (1)
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 Frequent 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

0 Kudos
4 Replies
jcarlson
MVP Frequent 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

0 Kudos
GlenOlliEsriUK
New Contributor

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