Python 如何修复错误';int';对象没有属性';文本';尝试制作单词云图像时

Python 如何修复错误';int';对象没有属性';文本';尝试制作单词云图像时,python,word-cloud,Python,Word Cloud,如何修复此错误,我正在尝试组合文本并创建word cloud图像 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 = " ".

如何修复此错误,我正在尝试组合文本并创建word cloud图像

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()
(区别是括号),因此如果一个不起作用,就使用另一个