Last active
April 3, 2019 15:09
-
-
Save danwaterfield/41e84f236b055f1b1d931ac3dcfc1d5c to your computer and use it in GitHub Desktop.
Merges n text files into a single csv, ignoring the headers in all but the first text file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
interesting_files = glob.glob("*.txt") | |
header_saved = False | |
with open('output.csv','w') as fout: | |
for filename in interesting_files: | |
with open(filename) 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