Created
July 14, 2019 13:06
-
-
Save IanHopkinson/f14f7be1019b8adb0ec5af6e1462a0ad to your computer and use it in GitHub Desktop.
csv concatenation
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 csv | |
mydir = "C:/Users/Nessa/Documents/Work/Coding/Test" | |
os.chdir(mydir) | |
all_filenames = [i for i in glob.glob("*.{}".format("csv"))] | |
all_data = [] | |
for f in all_filenames: | |
rows = csv.reader(f) | |
for row in rows: | |
all_data.append[row] | |
outfile = "C:/Users/Nessa/Documents/Work/Coding/Test/output.csv" | |
with open(outfile, 'w', newline='') as f: # This should work in Python 3, as I recall it is different in Python 2 | |
writer = csv.writer(f) | |
for row in all_data: | |
writer.writerow(row) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment