我正尝试使用python中的单词词典构建wordcloud。 这里是我的脚本Python词云 - IndexError:字符串索引超出范围
from wordcloud import WordCloud
words = {'Python':15, 'Pandas':13, 'R':16, 'Analyis':10, 'Scikit learn':19, 'Matplotlib':10}
wc = WordCloud()
wcloud = wc.generate_from_frequencies(words)
import matplotlib.pyplot as plt
plt.imshow(wcloud)
plt.axis("off")
plt.figure()
plt.imshow(wcloud)
plt.axis("off")
plt.show()
我收到错误,如
wcloud = wc.generate_from_frequencies(words)
File "...\Anaconda3\lib\site-packages\wordcloud\wordcloud.py", line 263, in generate_from_frequencies
frequencies = sorted(frequencies, key=item1, reverse=True)
IndexError: string index out of range
有人可以帮我如何解决这个问题。 我能够为文本文件生成wordcloud。但我想通过在Python字典(例如,在上面的脚本中所示)
我在Windows 7上运行,蟒蛇的Python 3.5,自定义单词频率使用Idlex和Spyder的IDE
正如一个供参考,这在当前的主分支被改变GitHub上。 –
@MadPhysicist:谢谢。我更新了答案,希望它不会误导未来的读者。 –