pandas模糊合并匹配名称列,包含重复项

pandas模糊合并匹配名称列,包含重复项,第1张

pandas模糊合并/匹配名称列,包含重复项

在我看来,这是一些pythonic的代码(在您的示例中),没有显式循环:

def get_donors(row):    d = donors.apply(lambda x: fuzz.ratio(x['name'], row['name']) * 2 if row['Email'] == x['Email'] else 1, axis=1)    d = d[d >= 75]    if len(d) == 0:        v = ['']*3    else:        v = donors.ix[d.idxmax(), ['name','Email','Date']].values    return pd.Series(v, index=['donor name', 'donor email', 'donor date'])pd.concat((fundraisers, fundraisers.apply(get_donors, axis=1)), axis=1)

输出:

      DateEmail        name donor name     donor emaildonor date0 2013-03-27 10:00:00          [email protected]    John Doe   John Doe          [email protected]  2013-03-01 10:39:001 2013-03-01 10:39:00          [email protected]    John Doe   John Doe          [email protected]  2013-03-01 10:39:002 2013-03-02 10:39:00          [email protected]  Kathy test   Kat test          [email protected]  2013-03-27 10:39:003 2013-03-03 10:39:00    [email protected]   Tes Ester    4 2013-03-04 10:39:00  [email protected]    Jane Doe   Jane Doe  [email protected]  2013-03-04 10:39:00


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5647639.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存