【发布时间】:2021-09-29 09:52:14
【问题描述】:
我有一个数据集,我想在地址上进行匹配,然后一旦我有了地址匹配,我还想知道与之关联的相关唯一 ID。
考虑这个例子:
df1 =
Address
123 road
abc lane
1 circle
7th avenue
4 high street
df2=
Address unique id
123 rd ID12345
abc lane ID12346
1 circle ID12347
7th ave ID12348
4 high st ID12349
df3 (result) =
Address match unique id
123 road 123 rd ID12345
abc lane abc lane ID12346
1 circle 1 circle ID12347
7th avenue 7th ave ID12348
4 high street 4 high st ID12349
到目前为止,我已经得到了这个代码:
address_list = df1['Address'].to_list()
address_search = df2['Address'].to_list()
mat1 = []
for i in address_search:
mat1.append(process.extract(i,address_list, limit=2))
df1['matches'] = mat1
我能够找到匹配项并将其附加到数据框,但我不确定如何搜索与找到的匹配项关联的相关唯一 id 列/行。
【问题讨论】:
标签: python pandas dataframe fuzzywuzzy