1

I am trying to append several pandas dataframes to a csv file but I cannot know ahead of time which dataframe will be appended first as they are each generated on different worker machines. I can append each one to pre-made empty csv file by doing: df.to_csv('test.csv', mode='a', header=False) but then my csv has no header and I just has data.

If I make header=True then I have copies of the header every time I append which is redundant since they are all the same. Is there any direct way to overcome this? I suppose I can check the file each time I want to append to see if there is a header but that feels inefficient.

guy
  • 1,021
  • 2
  • 16
  • 40

0 Answers0