首页 > 编程语言 > 详细

python csv模块写入有空行问题

时间:2017-08-27 11:39:30      阅读:421      评论:0      收藏:0      [点我收藏+]

默认在open(‘data.csv’,‘w+‘)模式下会有空行。在open后面添加newline=‘’ 即可解决。

https://stackoverflow.com/questions/41045510/pandas-read-csv-ignore-rows-after-a-blank-line

with open("data_a.csv","w",newline=‘‘) as csvfile:
    fieldnames = ["id","title"]
    writer=csv.DictWriter(csvfile,fieldnames=fieldnames)
    writer.writeheader()
    writer.writerow({"id":123,"title":"New title"})
    writer.writerow({"id":345,"title":"test "})

  

python csv模块写入有空行问题

原文:http://www.cnblogs.com/uxiuxi/p/7439869.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!