[python基础] python生成wordcloud并保存
1.核心包 #jieba、pandas用来处理数据,数据源以xls格式存储的,这里用pandas进行处理 import jieba from jieba import analyse import pandas as pd #scipy、wordcloud创建词云 from scipy.misc import imread from wordcloud import WordCloud from wordcloud import ImageColorGenerator #matpoltlib展示、保存生成的词云图 import matplotlib.pyplot as plt 2.过程 import jieba from jieba import analyse import pandas as pd import sys reload(sys) sys.setdefaultencoding( ' utf-8 ' ) # 1.stopwords def stop_words(): stop_dict = set() with open(u ' ./百度停用词列表.txt ' , ' r ' )as f: words = f.readlines() for word in words: stop_dict.add(word.strip().decode( ' utf-8 ' ))