我正在尝试将大约 600,000 个个人姓名(全名)与另一个拥有超过 8700 万个观察值(全名)的数据库进行匹配!
我第一次尝试使用fuzzywuzzy库太慢了,所以我决定使用更快的模块fuzzyset 。假设我有一台功能强大的计算机可以将所有数据集加载到内存中,我将使用包含 964 个观测值的测试文件与 50,000 个观测值进行匹配来执行以下操作:
import time
from cfuzzyset import cFuzzySet as FuzzySet
df1=pd.read_csv(file1,delimiter='|') # test file with 964 observations
df2=pd.read_csv(file2,delimiter='|') # test file with 50,000 observations to be matched against
a=FuzzySet() # allocate the FuzzySet object
for row in file2['name']:
a.add(str(row)) # Fill the FuzzySet object with all names from file2
start_time = time.time() # Start recording the time
dicto={'index':[],'name':[]} # Dictionary where I store the output
for names in file1['f_ofulln']:
dicto['index'].append(a.get(names)[0][0])
dicto['name'].append(a.get(names)[0][1])
print("--- %s seconds ---" % (time.time() - start_time))
>>> --- 39.68284249305725 seconds ---
使用更小的数据集(964 个观测值与 50,000 个观测值匹配),时间为39 秒。
但是,如果我想在整个数据集上执行此方法,这太慢了。
有谁知道如何提高运行时间?我认为 Cython 是不可能的,因为我已经导入了 Cython 版本的模糊集模块
非常感谢,
阿德里安