Re: Reading .csv files
- To: mathgroup at smc.vnet.net
- Subject: [mg32997] Re: [mg32971] Reading .csv files
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Sat, 23 Feb 2002 02:38:19 -0500 (EST)
- References: <200202220648.BAA12037@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
I set up an artificial example in Excel, and saved it as .txt. The values
are as follows (3 columns of values, where the first entry is the header):
In[1]:=
!!test.txt
Weight Size Height
3 22 122
6 46 345
8 31 768
2 59 322
9 54 879
8 21 455
3 40 657
5 44 369
7 56 221
Then I read them in with
In[2]:=
vals = Transpose[ReadList["test.txt", Word,
RecordLists -> True]]
Out[2]=
{{Weight,3,6,8,2,9,8,3,5,7},{Size,22,46,31,59,54,21,40,44,56},{Height,122,34
5,
768,322,879,455,657,369,221}}
and then I convert numbers into expressions (i.e., actual numbers), leaving
the header as text for each variable:
In[3]:=
({#[[1]], ToExpression[Rest[#]]} & ) /@ vals
Out[3]=
{{Weight,{3,6,8,2,9,8,3,5,7}},{Size,{22,46,31,59,54,21,40,44,
56}},{Height,{122,345,768,322,879,455,657,369,221}}}
I wonder if this is what you had in mind.
Tomas Garza
Mexico City
----- Original Message -----
From: "Coleman, Mark" <mark.coleman at dri-wefa.com>
To: mathgroup at smc.vnet.net
Subject: [mg32997] [mg32971] Reading .csv files
> Greetings,
>
> I often Import .csv data from spreadsheets. I normally just delete any
column or row headers,Import the data, then organize it into lists.
>
> Now say I have time series data oriented 'down' a column, i.e., each
column corresponds to all the obersvations for single variable, and the
first entry of each column is the variable name. How would I create a
Mathematica list for each varaible, where the list name (in Mathematica) is
the variable name from each column, and the list contents are the remaining
elements of the spreadsheet column?
>
> Thanks
>
> -Mark
>
- References:
- Reading .csv files
- From: "Coleman, Mark" <mark.coleman@dri-wefa.com>
- Reading .csv files