以Python的CSV文件格式导出
我正在尝试以CsV格式导出某些内容,但无法导出 下面是我在python中的任意想法以Python的CSV文件格式导出,python,csv,Python,Csv,我正在尝试以CsV格式导出某些内容,但无法导出 下面是我在python中的任意想法 script , file = argv emails = open(file,"r") #opens the file results = csv.writer(open("Results.txt" , "w")) #Creates a new file to show results. resultsList = [] here is the complete data and all for re
script , file = argv
emails = open(file,"r") #opens the file
results = csv.writer(open("Results.txt" , "w")) #Creates a new file to show results.
resultsList = []
here is the complete data and all
for results in resulsList:
results.writeline(result)
results.close()
emails.close()
现在…我需要以CSV格式保存results.txt中存储的所有数据
请提供您对此的反馈。
谢谢。您可以使用numpy和:
注意:您必须在
genfromtxt
中设置适当的分隔符,您正在向文件写入什么?您可以使用与写入Results.txt类似的方法将所有数据导出到文件中。只需确保每个字段用逗号分隔(检查CSV格式的基本规则),不要使用results.close()
,使用和open(“results.txt”,“r”)作为填充:
。良好做法;)问题是什么?您只需从文件中读取数据,对其进行解析,然后转储到另一个文件中。在您的for
语句之后,似乎出现了缩进错误……那么results.txt的内容是什么样子的?您是如何将其读入列表对象的?
import numpy as np
np.savetxt('results.csv', np.genfromtxt(file,delimiter='',dtype=None),delimiter=',')