image.png

    1. {"'剧情'": 4346.0, "'喜剧'": 2408.0, "'动作'": 1896.0, "'爱情'": 1761.0, "'惊悚'": 1287.0, "'犯罪'": 1173.0, "'冒险'": 1029.0, "'动画'": 906.0, "'奇幻'": 808.0, "'悬疑'": 806.0, "'科幻'": 736.0, "'恐怖'": 608.0, "'家庭'": 465.0, "'战争'": 385.0, "'传记'": 320.0, "'历史'": 313.0, "'同性'": 224.0, "'古装'": 221.0, "'音乐'": 157.0, "'武侠'": 126.0, "'情色'": 115.0, "'歌舞'": 115.0, "'运动'": 112.0, "'灾难'": 96.0, "'儿童'": 75.0, "'西部'": 64.0, "'黑色电影'": 17.0, "'真人秀'": 9.0, "'脱口秀'": 7.0, "'戏曲'": 6.0, "'舞台艺术'": 2.0, "'荒诞'": 2.0, "'鬼怪'": 1.0}
    1. import numpy as np
    2. import os
    3. import re
    4. from PIL import Image
    5. from os import path
    6. from wordcloud import WordCloud
    7. def makeImage(text):
    8. mask = np.array(Image.open("black.png"))
    9. wc = WordCloud(background_color="white", max_words=5000, mask=mask,
    10. font_path="simhei.ttf")
    11. # generate word cloud
    12. wc.generate_from_frequencies(text)
    13. # show
    14. plt.imshow(wc, interpolation="bilinear")
    15. plt.axis("off")
    16. plt.show()
    17. if __name__ == '__main__':
    18. # 获取数据:类型 - 频数
    19. data = pdef.genre_tj().sort_values('tj', ascending=False)
    20. # print(data)
    21. keys = data.index.tolist()
    22. values = data['tj'].tolist()
    23. dic = dict(zip(keys, values)) # 转换为dict
    24. # 生成词云图
    25. makeImage(dic)
    26. print(dic)

    black.png
    black.png