-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_oc.py
executable file
·63 lines (45 loc) · 892 Bytes
/
count_oc.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
#-*-coding:utf-8-*-
import csv
import unicodedata
import string
from parser import parser
file_name = "../../data/train.csv"
spam_reader = parser(file_name)
result = []
dico = {}
def add_to_dict(dico, element):
try:
dico[element] += 1
except:
dico[element] = 1
return dico
def max_count(dico):
maxx = 0
for key in dico.keys():
maxx = max(maxx, dico[key])
return maxx
def dico_to_list(dico):
l = map(lambda x : [dico[x]], dico)
return l
max_lb = 100000
count = 0
for row in spam_reader:
for e in row:
try:
float(e)
except:
if e == "YES" or e == "NO":
pass
else:
dico = add_to_dict(dico, e)
count += 1
if count == max_lb:
break
l = dico_to_list(dico)
print l
output_file = open('result_count.csv', 'w')
a = csv.writer(output_file)
a.writerows(l)
output_file.close()
c = d