问题在哪? 'int' object has no attribute 'read'

 AttributeError: 'int' object has no attribute 'read'

 问题出在最后的生词云的方法里,怎么改?

import pandas as pds
import jieba
import tkinter as tkt
import matplotlib
import matplotlib.pyplot as plt
import wordcloud as wd
from matplotlib.image import imread
#文件导入
text1=pds.read_excel(r"D:\CL_lab\数据采集与预处理实验\实验一\你好,李焕英 短评.xlsx")

#词条分词,转化列表
comment = text1["评论内容"]
comment_cut = comment.apply(jieba.lcut)

comment_word = []
for i in comment_cut:
    for j in i:
        comment_word.append(j)
# comment_word = [tkt._flatten(list(comment_cut))]
comment_Ser = pds.Series(comment_word)
word_counts = comment_Ser.value_counts()
#统计分词
# word_counts = {}
# for word in comment_word:
#     if len(word)>1:
#         word_counts[word] = word_counts.get(word,0)+1
print(word_counts)
#生成词云
pic = imread("D:\CL_lab\数据采集与预处理实验\实验一\素材\picture\horse.jpg")
w = wd.WordCloud(
    mask = pic,
    background_color = "white",
    font_path = "C:\Windows\Fonts\STXINGKA.ttc"
    )
w.fit_words(word_counts)
plt.imshow(w)
plt.axis("off")
plt.show()
w.to_file("D:\CL_lab\数据采集与预处理实验\实验一\评论-词云.jpg")

 

提供一下完整的错误信息,现在提供的信息并不能准确定位问题。

 

从你提供的错误信息看,可能是word_counts的数据结构不正确,确认一下word_counts是否是字典,是否符合fit_words的要求

 

请问是在哪一句程序导致的错误?