我正在将数据写入CSV,但是当前输出如下:
(第一行是标题)
A VC_s VC_i VT_s
1 (['Not Reported'],['reported'],['click'])
2 (['Not Reported'],['reported'],['click'])
所需的输出如下:
A VC_s VC_i VT_s
1 Not Reported reported click
2 Not Reported reported click
到目前为止,我得到的代码是:
ifile = 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])
我在做什么错,我该如何解决?看起来很容易解决,但我很沮丧。
最佳答案
entry = [VC_s, VC_i, VT_s]
rowAdd = tempfile.next()
ofile.writerow(rowAdd + entry)
关于python - Python:将列表写入每行中的各个列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4965841/