如何计算 pandas 数据框中基于字母的相似度
这是我的第一个数据帧 df1
Id Text
1 dFn
2 fiqe
3 raUw
这是我的第二个数据帧 df2
Id Text
1 yuw
2 dnag
相似度矩阵,列是来自 df1
的 Id
,行是 < code>Id from df2
1 2 3
1 0 0 0.66
2 0.5 0 0.25
注意:
(1,1)、(2,1) 和 (3,2) 中的 0
值,因为没有类似的字母
(3,1) 中的 0.25
值是因为 4 个字母“dnag”中只有 1 个来自 raUw
的字母(1/4 等于 0.25)
0.5 因 4 个字母中的 2 个相似而被计数
0.66
因 3 个单词中的 2 个相似而被计数
Here's my first dataframe df1
Id Text
1 dFn
2 fiqe
3 raUw
Here's my second dataframe df2
Id Text
1 yuw
2 dnag
Similarity Matrix, columns is Id
from df1
, rows is Id
from df2
1 2 3
1 0 0 0.66
2 0.5 0 0.25
Note:
0
value in (1,1), (2,1) and (3,2) because no letter similar
0.25
value in (3,1) is because of only 1 letter from raUw
avaliable in 4 letter `dnag' (1/4 equals 0.25)
0.5
is counted because of 2 of 4 letter similar
0.66
is counted because of 2 of 3 words similar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iiuc,一个选项是在嵌套列表中使用
set.Intersection
理解:输出:
IIUC, one option is to use
set.intersection
in a nested list comprehension:Output: