正在python入门写个词云,可是wordcount目前还是什么都没有,请问循环录入环节出了什么问题了吗?其中stopwords是一个包含常用非必要词语的内容集>>> import wordcloud>>> import collections>>> file=open('/Users/Downloads/word_cloud/98-0.txt')>>> wordcount={}>>> stopwords = set(line.strip() for line in open('/Users/Downloads/word_cloud/stopwords'))>>> for word in file.read().lower().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>>> wordcount
{}
添加回答
举报
0/150
提交
取消