MathGroup Archive 2011

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

Search the Archive

Re: read CSV

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117796] Re: read CSV
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Thu, 31 Mar 2011 04:05:03 -0500 (EST)
  • References: <imus7l$i3t$1@smc.vnet.net>

Alan wrote:

> I've received some files formatted like below.
> How can I read selected columns into a list?
> I'm coming from a background where I'd read in each line,
> discarding the first, then (in this case at least)
> split on the comma, and coerce the type.  So I'm happy
> to do that if I can figure out how.  (Naturally I could
> preprocess the data into a form that say ReadList
> likes better, but I'm looking for a pure Mathematica solution.)
>
> Thanks,
> Alan Isaac
>
> "x","y","color","pen down?"
> "0","0.26161459854014585","105","true"
> "1","0.2665251497682828","105","true"
> "2","0.29244385081680907","105","true"
> "3","0.31995416628471895","105","true"
>

Try this:

(Import["file.dat","CVS"]//Rest)/."true"->True

Output:
{{0, 0.261615, 105, True}, {1, 0.266525, 105, True},
 {2, 0.292444, 105, True}, {3, 0.319954, 105, True}}


-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: Re: Why Mathematica does not issue a warning when the calculations
  • Next by Date: Re: OT: structure of threads
  • Previous by thread: read CSV
  • Next by thread: Re: read CSV