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
I am assuming that you are going to appending one below other of two dataframe into single dataframe.
use below mentioned command to make it as single command
ans = pd.concat([df, df])
then you can make output into .csv file
I had a similar problem and after a god bit of searching, I didn't find any simple/elegant solution. The minimal fix that worked for me is:
import pandas as pd
with open('foo.csv') as f:
f.write('\n')
mydf.to_csv('foo.csv', index = False, header = False, mode='a')
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)