我有以下数据帧:
Sentence
0 Cat is a big lion
1 Dogs are descendants of wolf
2 Elephants are pachyderm
3 Pachyderm animals include rhino, Elephants and hippopotamus
我需要创建一个python代码,查看上面句子中的单词,并根据下面不同的数据帧计算每个单词的分数总和。你知道吗
Name Score
cat 1
dog 2
wolf 2
lion 3
elephants 5
rhino 4
hippopotamus 5
例如,对于第0行,分数将为1(cat)+3(lion)=4
我希望创建一个如下所示的输出。你知道吗
Sentence Value
0 Cat is a big lion 4
1 Dogs are descendants of wolf 4
2 Elephants are pachyderm 5
3 Pachyderm animals include rhino, Elephants and hippopotamus 14
nltk
你可能需要下载一些东西
然后设置词干和标记化
创建一个方便的词典
并生成分数
尝试将
findall
与re
re.I
一起使用首先,您可以尝试基于
split
和map
的方法,然后使用groupby
计算分数。你知道吗相关问题 更多 >
编程相关推荐