-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean_csv.py
More file actions
37 lines (33 loc) · 812 Bytes
/
Copy pathclean_csv.py
File metadata and controls
37 lines (33 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#script to clean up punctuation within strings
from __future__ import unicode_literals
from ftfy import fix_text
import sys
import csv
infile = open(sys.argv[1])
outfile = open(sys.argv[2], 'w')
writer = csv.writer(outfile)
for line in infile:
splits = line.split(",")
newline = []
newline.append(splits[0])
newline.append(splits[1])
comment = ','.join(splits[2:]).strip().strip('"').strip()
comment = comment.replace('""','"')
try:
comment = comment.decode("unicode-escape")
except:
pass
try:
comment = comment.decode("unicode-escape")
except:
pass
try:
comment = comment.decode("unicode-escape")
except:
pass
comment = fix_text(comment)
comment = comment.encode("utf-8")
newline.append(comment)
writer.writerow(newline)
infile.close()
outfile.close()