簡體   English   中英

如何提高數據幀內字符串相似度得分的計算速度?

[英]How to increase the speed of calculate string similarity score within dataframe?

我有一個數據框如下:

df = pd.DataFrame(data=[[1, 'Berlin',], [2, 'Paris', ],
                    [3, 'Lausanne', ], [4, 'Bayswater',],
                    [5, 'Table Bay', ], [6, 'Bejing',],
                    [7, 'Bombay',], [8, 'About the IIS']],
                    columns=['id', 'text'],)

我想用庫水母中的jaro_winkler來計算每個字符串與所有其余字符串的相似度得分,並輸出最相似度或得到相似度得分矩陣如下:

      str1 str2 str3
str1    1   0.6  0.7
str2    0.6  1   0.3
str3    0.7  0.3  1

我怎么能以快速的方式得到這個結果。 現在我只使用循環來比較每個並將結果存儲在列表中。

 def sim_cal(string1, string2):
     similar = jellyfish.jaro_winkler(string1, string2)
     return similar

但是如果數據變大,速度會很慢,所以如果有任何辦法可以加快速度嗎?

謝謝。

隨着Gensim你可以做這樣的事情這樣

我在這個定時示例中使用了GloVe

在此輸入圖像描述

不會說謊,這很有趣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM