How to force a new line when appending to a csv using python pandas .to_csv

前端 未结 3 950
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 17:38

When appending to csv, my first line is starting on the existing last line rather than a new line.

I keep searching SO, but I am just finding the basic use of openi

3条回答
  •  爱一瞬间的悲伤
    2021-01-12 18:20

    If your dataframe gets huge and you want to avoid concatenation you could go with

    import csv
    with open('foo.csv','ab') as out:
       writer=csv.writer(out)
       writer.writerow(())
    

    in a function or just as a snippet in your code. If you're not on Windows maybe you could avoid adding 'b' in open and open the file with just 'a' (append)

提交回复
热议问题