2

ArcGIS Pro, using Table to Table tool, I want to export to CSV. But one of my fields is a description field that often has commas in the content. When that is exported to CSV that uses commas as delimiters, it messes everything up.

Is there a way to specify that the delimiter for the export file should be a semi colon, or something else?

3
  • 1
    If it is still an option, you could save it as a dbf, or just open a dbf of a shapefile in Excel, or other spreadsheet software. You can then save the file with whatever delimiter you wish. Apr 28, 2021 at 21:38
  • I know... I was just hoping to avoid the additional manual step. And since the export concerned has over 6 million line items, Excel isn't really an option.
    – Maxcot
    Apr 28, 2021 at 22:02
  • A custom CSV writer is under a hundred lines of Python Toolbox code. CSV itself has a way to handle strings containing commas -- quotes -- though I prefer vertical bar delimiters.
    – Vince
    Apr 29, 2021 at 4:20

2 Answers 2

5

Create a pandas dataframe from your data and use to_csv. A workaround, but you can choose whatever delimiter you want:

import arcpy
import pandas as pd

fc = r'C:\GIS\data\Bakgrundskartor_LMV\Vagkartan.gdb\bs_riks'

#fields = ['KKOD', KATEGORI','SRIKT'] #Either list the field names manually
fields = [f.name for f in arcpy.ListFields(fc) if f.type not in ('GEOMETRY','OID') and not f.name.lower().startswith('sh')] #Or like this

df = pd.DataFrame.from_records(data=arcpy.da.SearchCursor(fc, fields), columns=fields)
sep = '|'
df.to_csv(path_or_buf=r'C:\GIS\data\bs_riks.csv', sep=sep, header=True, index=False)

enter image description here

2

There is an ArcGIS Pro Idea already submitted to Add More Delimiter Options in Table Export Tools (i.e., pipe delimiter):

There are several existing tools to export a table to a flat file .txt or .csv, such as copy rows, table to table, or export features rows to ASCII. The last option at least gives you the ability to choose comma, space, or semicolon delimiters. The first 2 tools default to commas with no configuration option.

Its current Status is In Product Plan and if you vote for it then you will be helping it to be implemented sooner rather than later.

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.