首页 > 解决方案 > 如何优化 pandas 中的 apply 函数以计算 levenshtein 距离?

问题描述

我正在尝试使用 apply 函数在两列之间找到 Levenshtein,但它非常慢。

from textdistance import levenshtein

temp['dist'] = temp.apply(lambda x: levenshtein.distance(x['address1'],x['address2']),axis=1)

733,000 行大约需要 2 分钟,我必须多次执行此操作。有没有办法使用矢量化来优化它?

标签: pythonpython-3.xpandasnumpy

解决方案


推荐阅读