Read a tab delimited txt file and write to separate column csv

Viewed 1684

I have a txt file that have several lines for the headers which are represented by a '#'.

Then I have three columns each with their own header that I want to copy into a csv file that will allow for each column to have their own column in the spreadsheet.

Currently all I am able to get is a file that has all three columns in one section of the csv.

import csv

infile = r'path\seawater_nh.txt'
outfile = r'path\emissivity_new.csv'

print "definitions successful"

in_txt = csv.reader(open(infile, 'rb'), delimiter = '\t')
out_csv = csv.writer(open(outfile, 'wb'))

out_csv.writerows(in_txt) 
1 Answers
Related