Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Import File Data with Headers' topicStudent Support Forum > General > "Import File Data with Headers"

Next Comment >Help | Reply To Topic
Author Comment/Response
Steve
08/20/12 10:25pm

Hi all,
I am new to Mathematica and trying to import data files into mathematica without pre-modifying them.

Presume I have the following csv file:

Header 1
Header 2
Header 3
Header 4
Header 5
DateTime,record, Temperature, RH, WindSpeed
6/7/2010 0:01,1,19,56,7
6/7/2010 0:05,2,20,61,8
6/7/2010 0:09,3,23,68,8
6/7/2010 0:12,4,20,61,8
6/7/2010 0:16,5,21,63,8
6/7/2010 0:20,6,23,68,8
6/7/2010 0:24,7,23,69,8
6/7/2010 0:27,8,22,65,8
6/7/2010 0:31,1,17,52,7
6/7/2010 0:35,2,17,51,7


I would like to import this file (presumably with the Import function with csv specified) while doing the following things:
- Skip the first 5 header lines
- Use the strings in the 6th line as the variable names for each column of data (i.e.
DateTime = {"6/7/2010 0:01", "6/7/2010 0:05", "6/7/2010 0:09", "6/7/2010 0:12", "6/7/2010 0:16", "6/7/2010 0:20", "6/7/2010 0:24", "6/7/2010 0:27", "6/7/2010 0:31", "6/7/2010 0:35"}
record = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2}
etc, etc.


I have done this in the past via the following process (shown in attached notebook):
- Remove the headers from the input data file
- Then use the following code to get it into the format required.
data = Import["datafile.csv","CSV"]
DateTime = data[[All, 1]]
record = data[[All, 2]]
temperature = data[[All, 3]]
RH = data[[All, 4]]
WindSpeed = data[[All, 5]]

Clearly this could get cumbersome and time consuming when files have a lot of data columns, which is what I am frequently dealing with.

Any help would be much appreciated.

Thanks
Steve

Attachment: MathematicaDataExample.nb, URL: ,

Subject (listing for 'Import File Data with Headers')
Author Date Posted
Import File Data with Headers Steve 08/20/12 10:25pm
Re: Import File Data with Headers Bill Simpson 08/22/12 11:10am
Next Comment >Help | Reply To Topic