我有一个包含英文、阿拉伯文和波斯文的Twitter文本数据集。我想用它创建一个词云,但是我的词云图像中阿拉伯文和波斯文单词显示为空白方块。我听说可以有三种方法解决这个问题:
使用不同的编码:我尝试了"UTF-8"、"UTF-16"、"UTF-32"和"ISO-8859-1",但没有解决问题
使用arabic_reshaper: 没有效果
使用同时支持三种语言的字体,比如"Arial"字体:在尝试将词云字体更改为Arial时,出现以下错误:
输入
wordcloud = WordCloud(font_path = 'arial',stopwords = stopwords, background_color = "white", max_font_size = 50, max_words = 100).generate(reshaped_text)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
输出
cannot open resource
这段代码在 Anaconda 中运行良好,但在 Google Colab 中无法运行。 需要解决的唯一问题是在 Google Colab 中应该输入什么路径作为 font_path。
wordcloud = WordCloud(font_path='/Library/Fonts/Arial.ttf').generate(text)
- undefined