Python WordCloud meet AttributeError: 'list' object has no attribute 'items'
Python WordCloud meet AttributeError: 'list' object has no attribute 'items'
当我使用WordCloud函数.fit_words()时,遇到了AttributeError: 'list' object has no attribute 'items'
。当我使用 .generate_from_frequencies() 时它也不起作用。如何弄清楚?所有建议将不胜感激。
代码:
wordcloud = WordCloud(font_path="simhei.ttf", background_color="white", max_font_size=80)
word_frequence = {x[0]: x[1] for x in words_stat.head(1000).values}
word_frequence_list = []
for key in word_frequence:
temp = (key, word_frequence[key])
word_frequence_list.append(temp)
wordcloud.fit_words(word_frequence_list)
plt.imshow(wordcloud)
word_frequence_list 是
[('诺兰', 89), ('电影', 48), ('战争', 43), ('一个', 43), ('配乐', 40), ('故事', 38), ('人', 36), ('拍', 31), ('时间', 30), ('叙事', 28).....
完整代码
已修改
当我使用WordCloud.fit_word()时,它显示AttributeError: 'list' object has no attribute 'items'。
当我使用 WordCloud.generate_from_frequencies() 时它也不起作用
如何解决?
谢谢 :)
代码:
frequency = [(u'知乎',5),(u'小段同学',4),(u'曲小花',3),(u'中文分词',2),(u'样例', 1)]
wordcloud = WordCloud().fit_words(频率)
错误
回溯(最近调用最后):
文件 "D:/VS_Project/Python/WordCloudSample/WCSample.py",第 19 行,位于
wordcloud = WordCloud().fit_words(频率)
文件 "C:\Users\AlphaGoMK\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\wordcloud.py",第 331 行,在 fit_words 中
return self.generate_from_frequencies(频率)
文件 "C:\Users\AlphaGoMK\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\wordcloud.py",第 350 行,在 generate_from_frequencies 中
频率=排序(frequencies.items(),键=item1,反向=真)
AttributeError: 'list' 对象没有属性 'items'
fit_words
want's your dictionary,不是 key/value 对的列表。可以直接传word_frequence
wordcloud.fit_words(word_frequence)
当我使用WordCloud函数.fit_words()时,遇到了AttributeError: 'list' object has no attribute 'items'
。当我使用 .generate_from_frequencies() 时它也不起作用。如何弄清楚?所有建议将不胜感激。
代码:
wordcloud = WordCloud(font_path="simhei.ttf", background_color="white", max_font_size=80)
word_frequence = {x[0]: x[1] for x in words_stat.head(1000).values}
word_frequence_list = []
for key in word_frequence:
temp = (key, word_frequence[key])
word_frequence_list.append(temp)
wordcloud.fit_words(word_frequence_list)
plt.imshow(wordcloud)
word_frequence_list 是
[('诺兰', 89), ('电影', 48), ('战争', 43), ('一个', 43), ('配乐', 40), ('故事', 38), ('人', 36), ('拍', 31), ('时间', 30), ('叙事', 28).....
完整代码
已修改
当我使用WordCloud.fit_word()时,它显示AttributeError: 'list' object has no attribute 'items'。 当我使用 WordCloud.generate_from_frequencies() 时它也不起作用 如何解决? 谢谢 :) 代码: frequency = [(u'知乎',5),(u'小段同学',4),(u'曲小花',3),(u'中文分词',2),(u'样例', 1)] wordcloud = WordCloud().fit_words(频率) 错误
回溯(最近调用最后): 文件 "D:/VS_Project/Python/WordCloudSample/WCSample.py",第 19 行,位于 wordcloud = WordCloud().fit_words(频率) 文件 "C:\Users\AlphaGoMK\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\wordcloud.py",第 331 行,在 fit_words 中 return self.generate_from_frequencies(频率) 文件 "C:\Users\AlphaGoMK\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wordcloud\wordcloud.py",第 350 行,在 generate_from_frequencies 中 频率=排序(frequencies.items(),键=item1,反向=真) AttributeError: 'list' 对象没有属性 'items'
fit_words
want's your dictionary,不是 key/value 对的列表。可以直接传word_frequence
wordcloud.fit_words(word_frequence)