MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Importing CSV (comma separated values) files?

  • To: mathgroup at
  • Subject: [mg13765] Importing CSV (comma separated values) files?
  • From: gwinn at (Joe Gwinn)
  • Date: Mon, 24 Aug 1998 05:07:15 -0400
  • Organization: Gwinn Instruments
  • Sender: owner-wri-mathgroup at

I have been trying to convince Mathematica 3.0.1 to ReadList an ordinary
CSV spreadsheet file, without luck.  It finds the file OK, then
complains of an unspecified "syntax error" while reading a number.  No
useful information is presented; all one knows is that it failed.

The file contains 240 lines, each line containing 240 non-negative
integer values separated by commas.  There are no decimal points or
plus/minus signs.  The values range fom 0 to 255.  For the record, this
is an output file from a CCD instrumentation TV camera used to measure
fiber optic nearfield flux distributions.

I have played with various combinations of RecordLists, WordSeparators,
and Number, to no avail.

Even though 240x240= 57,600 entries, Mathematica was not out of memory. 
The kernel has 25 MB, and the Front End has 10 MB, and the two
memory-use thermometers were less than 25% full.  If I take the same
file and edit it into Mathematica nested-list format and turn it into a
Mathematica notebook, Mathematica handles the data quite well, so the
problem is purely with the import function.

The actual output follows:

raw2Ddata = 
  ReadList[fullpath,Number,RecordLists->True (*,
WordSeparators->{","}*)]; Read::"readn": 
    "Syntax error reading a real number from \!\(\"FWB 4 GB:Gigabit \
Ethernet:Of\" \\[Ellipsis] \"urs:2D Image Data:50M_OFL.IMG\"\)."

All I can guess is that Mathematica expects numbers with decimals, and
isn't getting the decimals.  If that's true, it's a problem, because
the instruments don't do decimal numbers.   Is there an "Integer"
declaration for ReadLists?  "Integer" didn't work.

Anyway, has anybody managed to get this to work, or have any

Also, a comment for Wolfram:  Mathematica should be able to read and
write Microsoft Excel "text" format, and also CSV formatted files
directly and efficiently, using built-in functions, to enable access to
the vast range of scientific instruments and analysis packages, and
databases.  The present manual process is very slow and clumsy.

And, the error message needs some work.  One easy and very helpful trick
is to echo the offending line, and then put a line of ^^^ symbols under
the offending token:

Now is the t1me for ...
Number found where only letters were expected.

Joe Gwinn

  • Prev by Date: Re: Mathematica Crash
  • Next by Date: Re: simplifying complex polynomials
  • Previous by thread: Re: Importing CSV (comma separated values) files?
  • Next by thread: Re: Importing CSV (comma separated values) files?