1 回答

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
問題
問題并不完全是您只遇到NoneTypes
空字符串,它也可能引發(fā)此異常,正如您在實(shí)現(xiàn)中看到的那樣distance.get_jaro_distance
if not first or not second:
raise JaroDistanceException("Cannot calculate distance from NoneType ({0}, {1})".format(
first.__class__.__name__,
second.__class__.__name__))
選項(xiàng)1
嘗試用“NA”替換您的無類型和/或空字符串或從數(shù)據(jù)集中過濾它們。
選項(xiàng)2
對(duì)可能引發(fā)此異常的行使用標(biāo)志值/距離。在下面的例子中,我將利用999
from pyjarowinkler import distance
df['distance'] = df.apply(lambda d: 999 if not str(d['name_one']) or not str(d['name_two']) else distance.get_jaro_distance(str(d['name_one']),str(d['name_two']),winkler=True,scaling=0.1), axis=1)
添加回答
舉報(bào)