默认在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 "})