嘿,伙计们,我有一个脚本,可以比较每个可能的用户,并判断他们的文本有多相似:
dictionary = {
t.id: (
t.text,
t.set,
t.compare_string
)
for t in dataframe.itertuples()
}
highly_similar = []
for a, b in itertools.combinations(dictionary.items(), 2):
if a[1][2] == b[1][2] and not a[1][1].isdisjoint(b[1][1]):
similarity_score = fuzz.ratio(a[1][0], b[1][0])
if (similarity_score >= 95 and len(a[1][0]) >= 10) or similarity_score == 100:
highly_similar.append([a[0], b[0], a[1][0], b[1][0], similarity_score])
这个脚本运行大约需要15分钟,数据帧包含120k个用户,因此比较每个可能的组合需要相当多的时间,如果我只是在for循环上写pass,则需要2分钟来循环所有值.
我try 对if语句和模糊分数使用filter()和map(),但性能更差.我试着尽可能地改进 playbook ,但我不知道如何进一步改进.
非常感谢您的帮助!