Task: Use python to parse a CSV file and output the contents of a column into a text file.
Input file (in.csv):
one,two,three
four,five,six
Python script:
#!/usr/bin/env python
import csv
inputFile = open('in.csv', 'r')
inputReader = csv.reader(inputFile)
outputFile = open('out.txt', 'w')
outputWriter = csv.writer(outputFile)
for row in inputReader:
text = row[2]
# write column 3 to file
outputWriter.writerow(text)
outputFile.close()
inputFile.close()
Expected output
three
six
Actual output
t,h,r,e,e
s,i,x