Skip to content

Instantly share code, notes, and snippets.

@IanHopkinson
Created July 14, 2019 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanHopkinson/f14f7be1019b8adb0ec5af6e1462a0ad to your computer and use it in GitHub Desktop.
Save IanHopkinson/f14f7be1019b8adb0ec5af6e1462a0ad to your computer and use it in GitHub Desktop.
csv concatenation
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