7

我正在尝试绘制最常用单词的直方图arabic,但我无法找到一种方法来做到这一点。我能得到的只是切片字符,而不是编译后的单词。

这是我得到的一个例子:

在此处输入图像描述

import seaborn as sns

import pandas as pd

res = {
 'الذكاء': 8,
 'الاصطناعي': 9,
 'هو': 2,
 'سلوك': 1,
 'وخصائص': 1,
 'معينة': 1,
 'تتسم': 1
}

df = pd.DataFrame(res.items(), columns=['word', 'count'])

sns.set(style="whitegrid")
ax = sns.barplot(x="count", y="word", data=df)

如上图所示,我希望编译这些字符,就像字典中提到的那样。

4

1 回答 1

1

正如@Sheldore 所指出的那样,arabic_reshaper这似乎运行良好。bidi

import seaborn as sns
import pandas as pd
import arabic_reshaper
from bidi.algorithm import get_display

res = {
 'الذكاء': 8,
 'الاصطناعي': 9,
 'هو': 2,
 'سلوك': 1,
 'وخصائص': 1,
 'معينة': 1,
 'تتسم': 1
}

res2 = {get_display(arabic_reshaper.reshape(k)): v for k,v in res.items()}

df = pd.DataFrame(res2.items(), columns=['word', 'count'])

sns.set(style="whitegrid")
ax = sns.barplot(x="count", y="word", data=df)

带有阿拉伯标签的条形图

于 2021-07-02T08:03:26.850 回答