Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1344

Re: read CSV

From Peter Breitfeld <phbrf@t-online.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: read CSV
Date 2011-03-31 09:04 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <in1g3r$4o8$1@smc.vnet.net> (permalink)
References <imus7l$i3t$1@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

read CSV Alan <alan.isaac@gmail.com> - 2011-03-30 09:13 +0000
  Re: read CSV David <dlkeith@comcast.net> - 2011-03-31 09:03 +0000
  Re: read CSV David Bailey <dave@removedbailey.co.uk> - 2011-03-31 09:03 +0000
  Re: read CSV Peter Breitfeld <phbrf@t-online.de> - 2011-03-31 09:04 +0000
  Re: read CSV annetts729 <annetts729@gmail.com> - 2011-03-31 11:04 +0000

csiph-web