In [26]:
import collections
In [27]:
word_file = open(r'/Users/Harish/Documents/HK_Work/Python/DSE200x/Week-2/word_cloud/98-0.txt')
#stop_word = open(r'/Users/Harish/Documents/HK_Work/Python/DSE200x/Week-2/word_cloud/stopwords')
In [28]:
stopwords = set(line.strip()
for line in open(r'/Users/Harish/Documents/HK_Work/Python/DSE200x/Week-2/word_cloud/stopwords'))
In [29]:
wordcount = {}
In [30]:
for word in word_file.read().split():
word = word.replace(',','')
word = word.replace('.','')
word = word.replace('\"','')
word = word.replace('"','')
if word not in stopwords:
if word not in wordcount:
wordcount[word] = 1
else:
wordcount[word] += 1
In [31]:
d = collections.Counter(wordcount)
#print(d.most_common(10))
for word, count in d.most_common(10):
print(word, ": ", count)