Skip to content

Instantly share code, notes, and snippets.

@lewis-carson
Created May 3, 2018 18:58
Show Gist options
  • Save lewis-carson/e589222d95f80b0972018800fa2af008 to your computer and use it in GitHub Desktop.
Save lewis-carson/e589222d95f80b0972018800fa2af008 to your computer and use it in GitHub Desktop.
import os
import csv
import re
tot = ''
for i in os.listdir('csv'):
with open('csv/' + i) as f:
tot += f.read().replace(',\n', '\n')
print(f.read())
open('tot.csv', 'w+').write(tot)
tot = []
with open('tot.csv') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in spamreader:
if len(row) == 2:
tot.append(row[:2])
#print(row)
tot = [x for x in tot if x != []]
tot = [x for x in tot if x != ['', ''] ]
#print(tot)
for i in tot:
print(i)
open('parse.csv', 'a+').write(i[0] + ',' + i[1] + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment