I would like to use pd.write_csv to write \"filename\" (with headers) if \"filename\" doesn\'t exist, otherwise to append to \"filename\" if it exists. If I simply use co
with open(filename, 'a') as f: df.to_csv(f, mode='a', header=f.tell()==0)
it will add header when writes to the file first time