Merges n text files into a single csv, ignoring the headers in all but the first text file.
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