接下来是一些WordCloud包的利用杂记
from wordcloud import WordCloud
‘’‘ 引入jieba包对文本段进行合理切分’‘’
import jieba
import matplotlib.pyplot as plt
from collections import Counter
"""对于给定的一篇TXT来进行分析"""
mylist = list(open(r'C:\Users\15850\PycharmProjects\untitled\BIG DATA BASICS\wordcloud\12333.txt',encoding = 'utf8'))
'''得到所分析文本的列列表'''
wordlist = [','.join(jieba.cut(sentence)) for sentence in mylist]
new_text = ','.join(wordlist)
'''取出长度大于10个词的单词来作为词云的数据基础(考虑到英语虚词长度较长所以选择长度为10,但应该可能会有更好的分类标准)'''
target_text = [x for x in jieba.cut(new_text) if len(x)>=10]
frequences = dict(Counter(target_text).most_common())
wordcloud = WordCloud(background_color = 'azure').fit_words(frequences)
plt.imshow(wordcloud)
plt.axis('off')
plt.show()