Python问题求助
1, 读取bookcomments的内容(文档在附件中)2对读取内容处理(去除标点,处理重复的评论)(使用正则表达式相关方法进行处理)
3 完成分词操作
4 生成词云 是这样吗
import re
import jieba
import wordcloud
f = open('bookComments.txt')#读取
textlist=[]
reg = "[^0-9A-Za-z\u4e00-\u9fa5]" #标点
for eachline in f.readlines():
eachline = re.sub(reg,'',eachline) #去除标点
textlist.append(eachline)
textlist=list(set(textlist)) #去重
text = ''.join(textlist)
w = wordcloud.WordCloud(width=1000,\
font_path="msyh.ttc",height=700)
w.generate(" ".join(jieba.lcut(text)))
w.to_file("词云.png")
页:
[1]