Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #1349 > unrolled thread
| Started by | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| First post | 2011-03-31 09:06 +0000 |
| Last post | 2011-04-14 08:59 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: read CSV Bill Rowe <readnews@sbcglobal.net> - 2011-03-31 09:06 +0000
Re: read CSV Alan <alan.isaac@gmail.com> - 2011-04-14 08:59 +0000
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Date | 2011-03-31 09:06 +0000 |
| Subject | Re: read CSV |
| Message-ID | <in1g5r$4q5$1@smc.vnet.net> |
On 3/30/11 at 4:13 AM, alan.isaac@gmail.com (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"
If I were to do this entirely within Mathematica, I would read
the data in by doing
data=Import[filename, "CSV"];
Then select the columns I wanted by doing something like
data[[All,{1,4}]]
This would select the 1st and 4th columns.
Finally, I assume you want the numbers as numbers not strings.
So, I would convert the strings to numbers using ToExpression.
But frankly, I regard this as rather cumbersome. Since I use a
Mac and have an excellent text editor with a much better grep
engine than what is available in Mathematica, I would
pre-process the file using that tool into a form acceptable to
Get and use Get to read the file. In fact, I find it so handy to
use my text editor with Mathematica, I have set up a Mathematica
function that accepts a filename as an argument and has the file
opened up by my text editor. Additionally, I have grep macros
set up in the text editor to do the type of pre-processing needed.
Mathematica is a very powerful tool that can be used for a great
many purposes. But it is not the most efficient tool to use for
text processing.
[toc] | [next] | [standalone]
| From | Alan <alan.isaac@gmail.com> |
|---|---|
| Date | 2011-04-14 08:59 +0000 |
| Message-ID | <io6d1s$dq5$1@smc.vnet.net> |
| In reply to | #1349 |
Thanks for all the helpful suggestions on this list (and off list too)! Alan
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web