[Thread Prev][Thread Next][Index]

Re: [ferret_users] CSV file with commas in string fields



Hi Marco,

On Fri, Sep 4, 2020 at 11:35 PM Marco van Hulten <Marco.Hulten@xxxxxx> wrote:

"st1",2,3
"st1,2",2,3
st2,2,3

[ . . . ]
Two options are (1) using a different field separator (e.g. the tab
character) and (2) remove/replace the commas, but I prefer to avoid
reformatting of the CSV data.

I assume that you need only the numbers and that you don't need to load the strings into Ferret.

Then, my suggestion would be (although probably it's not what you are looking for) to use a scripting language like Ruby and Python to extract numbers from the CSV file.

Parsing a CSV file isn't a trivial task.  You'd be better off if you rely on a well-tested library.

Just to demonstrate how easy to handle CSV files in Ruby:

require 'csv'
headers, *row = CSV.read("mydata.csv")
# -> then row[0] is the first data row
# and row[0][0] is the first data item of the first data row.

I'm sure it's as easy in Python.

Ryo


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement