Python: Write list to individual columns in each row
I'm writing data to a CSV but the current output is as follows: (the top row is the headers)
A VC_s VC_i VT_s
1 (['Not Reported'],['reported'],['click'])
2 (['Not Reported'],['reported'],['click'])
The desired output is as follows:
A VC_s VC_i VT_s
1 Not Reported reported click
2 Not Reported reported click
The code I've got so far is:
ifile = 开发者_JAVA百科csv.reader(open("input.csv",'rb'))
shutil.copy("input.csv","temp")
tempfile = csv.reader(open("temp","rb"))
ofile = csv.writer(open("RESULTS.csv","ab"))
for row in ifile:
#do some table scraping stuff here
VC_s = str(cells[1].find(text=True))
VC_i = str(cells[2].find(text=True))
VT_s = str(cells[4].find(text=True))
entry = ([VC_s], [VC_i], [VT_s])
rowAdd = tempfile.next()
ofile.writerow(rowAdd + [entry])
What am i doing wrong and how can I fix this? It would seem like an easy fix but I am stumped.
entry = [VC_s, VC_i, VT_s]
rowAdd = tempfile.next()
ofile.writerow(rowAdd + entry)
You just want entry = [VC_s, VC_i, VT_s]
精彩评论