python 根据链家爬取的信息生成云词

#-*- coding: utf-8 -*-
'''
Created on 2017-10-12

@author: wbhuangzhiqiang
'''
import csv
from wordcloud import WordCloud#云词模块
import matplotlib.pyplot as plt#展示
#将链家爬取的数据
with open('D:\\PycharmProjects\\HZQTEST\\爬虫\\house.csv','r') as  vscfile:
    reads =csv.reader(vscfile)
    lst = []
    for  read  in reads:
        for i in read:
            lst.append(i)
mess =str(lst)
cloud = WordCloud(
    #设置字体,不指定就会出现乱码
    font_path='D:\\PycharmProjects\\HZQTEST\\zi.ttf',
    #设置背景色
    background_color='white',
    #允许最大词汇
    max_words=2000,
    #最大号字体
    max_font_size=40
    )
word_cloud = cloud.generate(mess) # 产生词云
plt.imshow(word_cloud)
plt.axis('off')
plt.show()

云词展示效果:

 

posted on 2017-10-12 23:19  HZQ_HZA  阅读(500)  评论(0编辑  收藏  举报

导航