{"'剧情'": 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}
import numpy as np
import os
import re
from PIL import Image
from os import path
from wordcloud import WordCloud
def makeImage(text):
mask = np.array(Image.open("black.png"))
wc = WordCloud(background_color="white", max_words=5000, mask=mask,
font_path="simhei.ttf")
# generate word cloud
wc.generate_from_frequencies(text)
# show
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
plt.show()
if __name__ == '__main__':
# 获取数据:类型 - 频数
data = pdef.genre_tj().sort_values('tj', ascending=False)
# print(data)
keys = data.index.tolist()
values = data['tj'].tolist()
dic = dict(zip(keys, values)) # 转换为dict
# 生成词云图
makeImage(dic)
print(dic)
black.png