写入csv

with open(birth_weight_file,'w') as f:
    writer=csv.writer(f)
    writer.writerow(birth_header)
    writer.writerows(birth_data)
    f.close()

这种写法最终的结果就是生成的csv文件每两行中间都有一行空白行,解决办法就是在open后面加上newline=''

写法:

with open(birth_weight_file,'w',newline='') as f:
    writer=csv.writer(f)
    writer.writerow(birth_header)
    writer.writerows(birth_data)
    f.close()

转载:
解决写入csv中间隔一行空行问题