Writing large Pandas Dataframes to CSV file in chunks

Solution:

header = True
for chunk in chunks:

    chunk.to_csv(os.path.join(folder, new_folder, "new_file_" + filename),
        header=header, cols=[['TIME','STUFF']], mode="a")

    header = False

Notes:

  • The mode="a" tells pandas to append.
  • We only write a column header on the first chunk.

Leave a Comment