Re: Importing a file and extracting data
- To: mathgroup at smc.vnet.net
- Subject: [mg131166] Re: Importing a file and extracting data
- From: Tomas Garza <tgarza10 at msn.com>
- Date: Sat, 15 Jun 2013 04:22:08 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <20130614090456.3F8026B6C@smc.vnet.net>
Let's do step by step. The result of importing your data should look like this (remember you have a series of 6 observations and then a series of 9): In[1]:= data=Import["experimentData.xlsx"]Out[1]= {{{Tc_Naph_84_2C,3.740 ns},{Tc_Naph_87_1C, 3.731 ns},{Tc_Naph_89_9C, 3.720 ns},{Tc_Naph_92_9C, 3.704 ns},{Tc_Naph_94_7C, 3.687 ns},{Tc_Naph_97_6C,3.694 ns},{Tc_Naph_83_2C, 3.758 ns},{Tc_Naph_83_4C, 3.750 ns},{Tc_Naph_86_4C, 3.728 ns},{Tc_Naph_88_1C, 3.725 ns},{Tc_Naph_90_2C,3.716 ns},{Tc_Naph_93_1C, 3.704 ns},{Tc_Naph_94_7C, 3.673 ns},{Tc_Naph_97_7C, 3.684 ns},{Tc_Naph_97_9C, 3.665 ns}}} First, we get rid of the parentheses to have a neater view, where everything is a string: In[2]:= data=Partition[Flatten[data],2]Out[2]= {{Tc_Naph_84_2C, 3.740 ns},{Tc_Naph_87_1C, 3.731 ns},{Tc_Naph_89_9C, 3.720 ns},{Tc_Naph_92_9C, 3.704 ns},{Tc_Naph_94_7C, 3.687 ns},{Tc_Naph_97_6C, 3.694 ns},{Tc_Naph_83_2C, 3.758 ns},{Tc_Naph_83_4C, 3.750 ns},{Tc_Naph_86_4C, 3.728 ns},{Tc_Naph_88_1C, 3.725 ns},{Tc_Naph_90_2C, 3.716 ns},{Tc_Naph_93_1C, 3.704 ns},{Tc_Naph_94_7C, 3.673 ns},{Tc_Naph_97_7C, 3.684 ns},{Tc_Naph_97_9C, 3.665 ns}} For each of the temperature data, throw away the first 8 characters and the last one (the C), and then replace the "_" with a "." Convert all to numbers using ToExpression: In[3]:= step1=Table[ToExpression[StringReplace[StringDrop[StringDrop[data[[j,1]],8],-1],"_"->"."]],{j,1,15}]Out[3]= {84.2,87.1,89.9,92.9,94.7,97.6,83.2,83.4,86.4,88.1,90.2,93.1,94.7,97.7,97.9} For the time data, drop the "ns" and convert to numbers In[4]:= step2=Table[ToExpression[StringDrop[data[[j,2]],-2]],{j,1,15}]Out[4]= {3.74,3.731,3.72,3.704,3.687,3.694,3.758,3.75,3.728,3.725,3.716,3.704,3.673,3.684,3.665} Finally, rearrange the results into the two desired sets: In[5]:= run1=Take[Transpose[{step1,step2}],6]Out[5]= {{84.2,3.74},{87.1,3.731},{89.9,3.72},{92.9,3.704},{94.7,3.687},{97.6,3.694}} In[6]:= run2=Take[Transpose[{step1,step2}],-9]Out[6]= {{83.2,3.758},{83.4,3.75},{86.4,3.728},{88.1,3.725},{90.2,3.716},{93.1,3.704},{94.7,3.673},{97.7,3.684},{97.9,3.665}} -Tomas > From: howardfink at gmail.com > Subject: Importing a file and extracting data > To: mathgroup at smc.vnet.net > Date: Fri, 14 Jun 2013 05:04:56 -0400 > > I have a series of files of this form: > > June 7, 2013 > Tc+Naphthalene vs Temperature (oC) > > Run 1 > Tc_Naph_84_2C 3.740 ns > Tc_Naph_87_1C 3.731 ns > Tc_Naph_89_9C 3.720 ns > Tc_Naph_92_9C 3.704 ns > Tc_Naph_94_7C 3.687 ns > Tc_Naph_97_6C 3.694 ns > > > Run 2 > Tc_Naph_83_2C 3.758 ns > Tc_Naph_83_4C 3.750 ns > Tc_Naph_86_4C 3.728 ns > Tc_Naph_88_1C 3.725 ns > Tc_Naph_90_2C 3.716 ns > Tc_Naph_93_1C 3.704 ns > Tc_Naph_94_7C 3.673 ns > Tc_Naph_97_7C 3.684 ns > Tc_Naph_97_9C 3.665 ns > > > > > I used an Import command to read in the file, but now I am just sitting and staring, without a clue how to get the 84_2 converted to the number 84.2,etc. and ending up with two lists: Run 1 and Run 2, consisting of pairs of temperature and time. The temperature will eventually be converted to 1/absolute temperature. > > I've read lots and lots of help, thumbed through dozens of pages of a Mathematica 5 manual, and don't know where to start. I'm trying to help a 90-year-old chemistry professor, who is currently using a calculator, but there will be dozens of runs of this experiment. >
- References:
- Importing a file and extracting data
- From: howardfink@gmail.com
- Importing a file and extracting data