-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanCSV.py
executable file
·30 lines (26 loc) · 931 Bytes
/
cleanCSV.py
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
import csv
import string
def remove_quotes(s):
return ''.join(c for c in s if c not in ('"', "'"))
'''
with open('FCBCollegeList.csv', 'rU') as f, open("fixedCollegeList.csv","wb") as g:
reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
writer = csv.writer(g, quoting=csv.QUOTE_ALL)
for line in reader:
writer.writerow([remove_quotes(elem) for elem in line])
with open('fixedCollegeList.csv', 'rU') as f:
reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
aList = [[x.strip() for x in row] for row in reader]
'''
lines = open('FCBCollegeList.txt').readlines()
f2 = open('FCBCollegeList.txt',"w")
for line in lines:
ele = line.split("\t")
line = ""
for i in range(len(ele)):
if "\xff" in ele[i]:
ele[i] = ele[i].replace("\xff","")
line += ele[i] +"\t"
#line = line.replace("\xEF\xBF\xBD","")
line = filter(lambda x: x in string.printable, line)
f2.write(line)