Python对抓取到的网易云音乐评论进行词云分析 【2】
首先在music_comments.csv文件中 复制这一列内容到b.txt

然后创建cituyun.py
# -*- coding: utf-8 -*- from wordcloud import WordCloud import matplotlib.pyplot as plt from wordcloud import WordCloud,ImageColorGenerator,STOPWORDS import cv2# 处理图像的函数 text= open("b.txt",encoding='utf-8').read() """ text = ''' The 抱抱 Zen of LOVE 抱抱 Python, 快乐 by Tim 玲小姐 Peters 公众号 Python 最好的 语言 语言 一辈子 is better LOVE than 一辈子. 玲小姐 is 爱你 than implicit.爱你 玲小姐 王先生 is 爱你 than complex. 一辈子 is 王先生 than complicated. 二中 is 玲小姐 我想你了 than nested. 二中 王先生 清湖 is 胜于 than 清湖. 思旺 counts. 想你 Special 玲小姐 我想你了 aren't special enough 思旺 break 思旺 rules. 别生气 practicality beats 厨艺好. Errors should 我想你了 never pass 小龙虾 silently. 运营 别生气 explicitly 好不好. LOVE In the face of ambiguity, 程序员 the 厨艺好 to guess.龙华 There 快乐 should be one-- 我想你了 and preferably 红烧肉 only 武汉 one 小龙虾--obvious way to do it.运营 Although 共享单车 way may not 我想你了 be obvious at first unless you're Dutch. 新媒体 地铁 Now is better 红烧肉 than never. 程序员 Although 共享单车 is often 高铁 than 海南 now. 高铁 地铁 If the impleme 武汉 ntation 想你 is hard to explain, it's a bad idea. 想你了 If 成都 implementation is 想你 easy to explain, it may be a good idea. Namespaces are 端午one 端午 honking 王先生 great idea -- 成都 do more of those! 想你了 深圳 晚安 海南 新媒体 ''' """ # the font from github: https://github.com/adobe-fonts font = r'C:\Windows\Fonts\simfang.ttf' stopwords_path5 = 'stop_words_eng.txt' stopwords_path6 = 'ENstopwords891.txt' stopwords_path7 = 'ENstopwords.txt' listOfFileName = [] listOfFileName.append(stopwords_path5) listOfFileName.append(stopwords_path6) listOfFileName.append(stopwords_path7) sw = listOfFileName back_coloring = cv2.imread("2.png") image_colors = ImageColorGenerator(back_coloring) wc = WordCloud(collocations=False, background_color="white", mask=back_coloring, stopwords=sw , #电脑没有上面的去掉无用词,可以不用加,免得报错 font_path=font, #width=1400,#图幅宽度 #height=1400, margin=2, scale=5,# 比列放大 数值越大 词云越清晰 ).generate(text.lower()) plt.imshow(wc) plt.axis("off") plt.show() wc.to_file('muouren.png') # 把词云保存下来
2.png图片

最后生成效果:

可以不用2.png 生成效果:

    如果人生还有重来,那就不叫人生。
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号