[英]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
但是如果數據變大,速度會很慢,所以如果有任何辦法可以加快速度嗎?
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.