zoukankan      html  css  js  c++  java
  • 数据词云(wordcloud)

    import pandas as pd
    import numpy as np
    from pandas import Series
    from pandas import DataFrame
    from wordcloud import WordCloud,ImageColorGenerator
    import matplotlib.pyplot as plt
    import jieba
    from PIL import Image

    df =pd.read_csv('ZHILIAN_SPIDER.csv',header=None,index_col=False,names=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])

    b=df[15]
    c=[ str(i).replace('元/月','').replace('以下','').replace('以上','').split('-') for i in b if i !='面议']
    d=[ float(ii) for i in c for ii in i if ii !='nan']
    avg=sum(d)/len(d)

    #wordcloud生成词云
    a=str(df[16])

    '''
    #普通版
    cut_text = " ".join(jieba.cut(a)) #分词
    wordcloud = WordCloud(font_path="C:/Windows/Fonts/simfang.ttf",background_color="white",width=860, height=860, margin=2).generate(cut_text )
    plt.imshow(wordcloud,interpolation="bilinear")
    plt.axis("off")
    plt.show()
    wordcloud.to_file('test1.png')
    '''

    #图像模仿版
    path_img = r"1.jpg"
    background_image = np.array(Image.open(path_img))
    cut_text = " ".join(jieba.cut(a)) #分词
    # 设置字体,不然会出现口字乱码,文字的路径是电脑的字体一般路径,可以换成别的
    # mask参数=图片背景,必须要写上,另外有mask参数再设定宽高是无效的
    wordcloud = WordCloud(font_path="C:/Windows/Fonts/simfang.ttf",background_color="white",mask=background_image).generate(cut_text)
    # 生成颜色值
    image_colors = ImageColorGenerator(background_image)
    # 下面代码表示显示图片
    plt.imshow(wordcloud.recolor(color_func=image_colors), interpolation="bilinear")
    plt.axis("off")
    plt.show()
    wordcloud.to_file('test2.png')




  • 相关阅读:
    BZOJ 1565 植物大战僵尸
    BZOJ 1497 最大获利(最大权闭合子图)
    BZOJ 1070 修车(最小费用流)
    BZOJ 2879 NOI2012美食节
    PHPCMS模板里面使用自定义函数
    邓_phpcms_数据库
    邓_ phpcms_
    dedecms====phpcms 区别==[工作]
    邓_html_图片轮播
    dedecms_插件
  • 原文地址:https://www.cnblogs.com/xdlzs/p/11534392.html
Copyright © 2011-2022 走看看