Python:将列表写入每行中的各个列
我正在将数据写入 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])
我做错了什么以及如何解决这个问题?这似乎是一个简单的解决办法,但我很困惑。
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 = 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需要
entry = [VC_s, VC_i, VT_s]
You just want
entry = [VC_s, VC_i, VT_s]