You can use ast.literal_eval
and itertools.izip
for this:
from ast import literal_eval
from itertools import izip #For memory efficiency use this over zip
with open('file.txt') as f:
#Firstly collect the first column from each line in a list
column_1 = [line.split(None, 1)[0] for line in f if not line.isspace()]
f.seek(0) #Move the file pointer to the start of the file
# Now we need to use the second column from each line and convert it to
# a Python list using ast.literal_eval.
# Then we pass each of these lists to izip with `*` to get a transpose
# of the data.
for x in izip(*(literal_eval(line.split(None, 1)[1]) for line in
f if not line.isspace())):
#Here x contains items on the same index from each list.
print '"Coordinates:" {0}, {1}'.format(*x[0][:2])
for a, b in izip(column_1, x):
print "{0}, {1}".format(a, b[-1])
print
Output:
"Coordinates:" 0.00988, 0.00015441
2802, 44.072
2804, 56.284
2806, 68.856
3794, 65.442
"Coordinates:" 0.01203, 0.00018802
2802, 43.108
2804, 55.15
2806, 67.409
3794, 63.987
"Coordinates:" 0.01385, 0.00021648
2802, 42.286
2804, 54.18
2806, 66.177
3794, 62.749
"Coordinates:" 0.01546, 0.0002416
2802, 41.555
2804, 53.313
2806, 65.081
3794, 61.648
"Coordinates:" 0.01692, 0.00026435
2802, 40.889
2804, 52.521
2806, 64.082
3794, 60.646
"Coordinates:" 0.01826, 0.00028529
2802, 40.274
2804, 51.788
2806, 63.161
3794, 59.723
Replace {0}
with {0:.15f}
wherever you need to display upto 15 decimal places.