I have the following CSV file
The data is not stored in an ideal format. The first row has some pretty useless and repeated tags.
What I am trying to do is to get something similar to the following into a file.
P1000, N400
P1001, N401
P1001,N402
P1002,N500
Two challenges I am having:
#1. I want to skip the first row
#2. I would like to skip fields 0 and 6 so that if a value is not blank then it will write a line with the PCID and the value.
I have the following code:
import csv, sys
filename = "test.csv"
reader = csv.reader(open(filename, "rb"))
try:
for row in reader:
PCID = row[6]
for field in row:
if field != "":
print PCID,field
except csv.Error, e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))