ここに私が提案しているものがあります。まず、完全なデカルトは2つのDFSに参加:
df1.loc[:, 'MergeKey'] = 1 #create a mergekey
df2.loc[:, 'MergeKey'] = 1 #it is the same for both so that when you merge you get the cartesian product
#merge them to get the cartesian product (all possible combos)
merged = df1.merge(df2, on = 'MergeKey', suffixes = ['_1', '_2'])
その後、各コンボ用ファズ比を計算します。
def fuzzratio(row):
try: #avoid errors for example on NaN's
return fuzz.ratio(row['Billing Country_1'], row['Billing Country_2'])
except:
return 0. #you'll want to expiriment w/o the try/except too
merged.loc[:, 'Ratio'] = merged.apply(fuzzratio, axis = 1) #create ratio column by applying function
今、あなたはdf1['Billing Country']
のすべての可能な組み合わせの間の比率でDFを持っている必要がありますおよびdf2['Billing Country']
。一度そこにフィルタを設定すると、割合が100%のものを得ることができます。
出典
2016-05-03 19:09:53
Sam
。 – Sam
サム - あなたは、Billingの国で外側のマージを行い、各組み合わせのファジーマッチを探すことをお勧めしますか? –