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.
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 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))