from pyecharts import options as opts
from pyecharts.charts import WordCloud
import pandas as pd
df=pd.read_excel('对应的excel文件名') #excel文件需要和该代码在统一文件夹下,如果没在,需填入文件路径
data=df.values
c = (
WordCloud()
.add(
"",
data,
word_size_range=[20, 100],
textstyle_opts=opts.TextStyleOpts(font_family="cursive"),
)
.set_global_opts(title_opts=opts.TitleOpts(title="热点词"))
.render("词云图.html")
)
这个是我在初次学习pyecharts时,发现pyecharts的词云图代码使用的数据直接是数组,需要手敲进去,但按我的需求,需要调用自己爬虫后的词频统计文件中的数据,根据词频来绘制词云图。
经过不断查询(我的python没怎么学基础,见笑了:)),发现可以调用pandas库使用pd.read_excel来调用。
希望能帮到你!