First of all, in the QQ message manager will be a person or all of the chat records exported into TXT format, put in F disk;
Running the following Python code requires the installation of Jieba and Wordcloud two libraries.
Import Matplotlib.pyplot as Plt from Wordcloud import wordcloud import Jieba from Wordcloud import Wordcloud, Imagecolorge Nerator import OS import numpy as NP import pil.
Image as Image newtext = [] #打开F盘下的聊天记录文件e. txt for word in open (' F:\\e.txt ', ' R ', encoding= ' Utf-8 '): tmp = Word[0:4] #print (TMP) if (tmp = = "2017" or tmp = = "= = = = = = = = =" = = Word[0:2] #print (tm P) if (tmp[0] = = ' [' or tmp[0] = = '): #过滤掉图片和表情, for example [picture],/cute continue newtext.append (word) #将过滤掉图片和表情和时间信息
and QQ name the remainder of the text is rewritten in the Ab.txt file under F disk to go with open (' F:\\a2.txt ', ' W ', encoding= ' Utf-8 ') as F:for i in Newtext:f.write (i) #打开新生成的聊天记录文件 Text = open (' F:\\a2.txt ', ' r ', encoding = ' utf-8 '). Read () Word_jieba = jieba.cut (text, cut_all=true) word_sp Lit = "". Join (Word_jieba) #找一张小黄人logo图来生成配色方案, small yellow person logo map small yellow person. jpg path under f:\\ disk alice_coloring = Np.array (Image.open ( Os.path.join (' f:\\ ', ' Little yellow man. jpg ')) My_wordcloud = Wordcloud (background_color= "White", max_words=2000, Mask=alice_Coloring, max_font_size=40, random_state=42, font_path= ' c:/windows/fonts /simhei.ttf ') \ Generate (word_split) image_colors = Imagecolorgenerator (alice_coloring) plt.imshow (my_ Wordcloud.recolor (color_func=image_colors)) plt.imshow (My_wordcloud) plt.axis ("Off") Plt.show ()
The generated word cloud is as follows:
Filter writing is not good, the results of the chat recorded in the QQ expression did not filter out, still need to improve.