我csv
为会计墨盒创建了一个文件
import csv
with open('cartridge_accounting.csv', 'w') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Date', 'Model', 'Mark'])
filewriter.writerow(['2019-02-26', 'CE255X', 'nv print'])
filewriter.writerow(['2019-02-26', 'CE255X', 'nv print'])
结果,文件被写入了一行
['Date', 'Model', 'Mark']
[]
['2019-02-26', 'CE255X', 'nv print']
[]
['2019-02-26', 'CE255X', 'nv print']
[]
请告诉我如何摆脱它。以及如何添加索引行使文件如下所示:
['Date', 'Model', 'Mark']
[0,'2019-02-26', 'CE255X', 'nv print']
[1,'2019-02-26', 'CE255X', 'nv print']
[2,'2019-02-26', 'CE255X', 'nv print']
[3,'2019-02-26', 'CE255X', 'nv print']
该文档建议像这样解决它
对于此类任务, Pandas模块是理想的:
结果: