I am trying to parse data from a file which has two sets of data included in it. The file has header information for the first 40 lines of the file and then is followed by 1000 lines of two columns of data. An additional file has been appended to the file with the same format. That is, lines 1041 through 1081 have the second file's header information, followed by 1000 lines of two column data. The first column in for both sections of data is the same. Therefore, I want to parse the data file to remove the header section and save the data to a 3x1000 array.
The file is organized as:
Line 1: //Header information
Line 2: //Header information
...
Line 40: 1.000e3 -4.000e-3
Line 41: 1.001e3 -4.324e-3
...
Line 1000: 10.000e3 -78.678e-3
Line 1001: //Header Information
Line 1002: //Header Information
Line 1041: 1.000e3 -16.000e-3
Line 41: 1.001e3 -14.324e-3
...
Line 2000: 10.000e3 -22.178e-3
I want to parse on the columned data and output to an array with the format of
[1.000e3, -4.000e-3, -16.000e-3]
[1.001e3, -4.432e-3, -14.423e-3]
...
[10.00e3. -78.678e-3, -22.178e-3]
I have tried the following: DATA = [[0 for x in xrange(3)] for x in xrange(10000)]
for i in sort(os.listdir('.')):
for lines in range(0, 39):
dataFile.readline()
for lines in range(0, 10000):
readData = dataFile.readline()
dataLine = readData.split()
DATA[0].append(dataLine[0])
DATA[1].append(dataLine[1])
for lines in range(0, 39):
dataFile.readline()
for lines in range(0, 10000):
readData = dataFile.readline()
dataLine = readData.split()
DATA[2].append(dataLine[1])
dataFile.close()
Thanks for your help in advance.
range(0, 39)only has 39 values, not 40. Andrange(0, 10000)obviously has 10000 lines, not 1000.