Skip to content

Instantly share code, notes, and snippets.

@brockthebear
Created May 18, 2017 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brockthebear/a3f384304fbb8667627e93e53af86632 to your computer and use it in GitHub Desktop.
Save brockthebear/a3f384304fbb8667627e93e53af86632 to your computer and use it in GitHub Desktop.
Combine multiple CSVs into one.
import glob
files = glob.glob("*.csv")
header_saved = False
with open('output.csv', 'w') as fout:
for file in files:
with open(file) as fin:
header = next(fin)
if not header_saved:
fout.write(header)
header_saved = True
for line in fin:
fout.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment