I have a csv file (tab delimited) whose sample format is:
"col1 col2 col3 col4 col5"
"15 AMC 0.0 0.0 0.0"
n = 3
n = 3 # number of values to be extracted from header of csv.Will vary
file = open('file1.csv','rU')
read = csv.reader(file,delimiter='\t')
row_number = 0
for row in read:
if row_number == 0:
header = row
I assume that the double quotes (
") are in the file as you show them, so they will quote the whole line and delimiters are ignored within quoted strings. You would have to strip those quotes before handing the lines to the csv reader:
file = open('file1.csv','rU') lines = [line.strip().strip('"') for line in file] # strip white space, too, to be sure read = csv.reader(lines, delimiter='\t') # any iterable producing strings will do in the reader constructor