python---词云生成代码

import jieba
import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud,STOPWORDS
import imageio

'''此函数将数据转化为列表格式'''
def get_wordList():
    df = pd.read_csv(“文件路径”)
    wordList = df['某一列'].tolist()
    return wordList

'''此函数将生成对应列的词云'''
def get_wordClound(mylist):
    word_list = ["".join(jieba.cut(sentence))for sentence in mylist]
    new_text = ''.join(word_list)
    pic_path = '/路径/词云.png'
    img_mask = imread(pic_path)
    wordcloud = WordCloud(background_color = 'white',
    font_path = '/路径/msyh.ttc',mask = img_mask,stopwords=STOPWORDS,).generate(new_text)
    plt.imshow(wordcloud)
    plt.axis("off")
    plt.show()

'''主函数入口'''
if __name__ == '__main__':
    wordList = get_wordList()
    get_wordClound(wordList)

你可能感兴趣的:(python,python,可视化,正则表达式)