如何修复此错误,我正在尝试合并文本并创建一个文字云图像。
from os import path
from PIL import Image
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
text = []
cb = cbData #text dataset
tc = 0
for t in cb.text:
text.append(t)
tc += 1
all_text = " ".join(t for t in text)
print("Total words in all posts: ", len(all_text))
这是错误:
----> 3 for t in cb.text:
AttributeError: 'int' object has no attribute 'text'
该错误只是告诉您正在尝试使用不存在的属性或方法。我建议列出确实存在的属性/方法,并找出从那里做的事情。这可以这样做:
# code that generates variable "cb" (not supplied in post)
print(dir(cb))
现在,查看输出并查看您应该尝试访问的方法/属性。也许它就像.Text
或.text()
一样简单
注意:生成的列表不会告诉你它是否应该是.text
或.text()
(差异是括号)所以如果一个不起作用只是使用另一个!