Last active
September 27, 2016 20:30
-
-
Save tmaybe/8931979 to your computer and use it in GitHub Desktop.
strip quoted newlines from a folder-full of CSV files
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 | |
import re | |
import glob | |
for input_filename in glob.glob("./*.csv"): | |
print("working on {}".format(input_filename)) | |
with open(input_filename, 'rU') as infile: | |
output_filename = "./strp-{}.csv".format(input_filename.lower().rstrip(".csv").lstrip("./")) | |
with open(output_filename, 'a') as outfile: | |
output_writer = csv.writer(outfile) | |
for input_row in csv.reader(infile): | |
for input_pos in range(len(input_row)): | |
input_row[input_pos] = re.sub('\n', ' ', input_row[input_pos]) | |
output_writer.writerow(input_row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment