问题描述
import pandas as pd
import recordlinkage as rl
lst_left = [...]
lst_right = [...]
df_left = pd.DataFrame(lst_left,columns=pd.Index(["city_id","street_name"]))
df_right = pd.DataFrame(lst_right,"street_name"]))
indexer = rl.Index()
indexer.block("city_id")
pairs = indexer.index(df_left,df_right)
compare = rl.Compare(indexing_type="label")
compare.string("street_name","street_name",method="damerau_levenshtein",threshold=0.7)
features = compare.compute(pairs,df_left,df_right)
matches = features[features[0] == 1.0]
我得到匹配对 MultiIndex
Out[4]:
0
0 0 1.0
1 1 1.0
2 2 1.0
4 3 1.0
6 5 1.0
7 6 1.0
8 7 1.0
10 8 1.0
12 9 1.0
13 10 1.0
14 11 1.0
15 12 1.0
现在我想左连接(sql 左外连接)df_left 和 df_right 数据帧基于那些匹配对保持 df_left 数据帧中不匹配的元素。
我该怎么做?
附言只获取匹配的记录,我使用
df_left.loc[matches.index.get_level_values(0)].reset_index().merge(df_right.loc[matches.index.get_level_values(1)].reset_index(),how="left",left_index=True,right_index=True)
但我不知道如何从左侧 DataFrame 合并和保留不匹配的行。
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)