Searching one Python dataframe / dictionary for fuzzy matches in another dataframe

后端 未结 2 657
北恋
北恋 2021-01-03 03:34

I have the following pandas dataframe with 50,000 unique rows and 20 columns (included is a snippet of the relevant columns):

df1:

          


        
2条回答
  •  孤城傲影
    2021-01-03 04:26

    You should be able to iterate over both dataframes and populate either a dict of a 3rd dataframe with your desired information:

    d = {
        'df1_id': [],
        'df1_prod_desc': [],
        'df2_id': [],
        'df2_prod_desc': [],
        'fuzzywuzzy_sim': []
    }
    for _, df1_row in df1.iterrows():
        for _, df2_row in df2.iterrows():
            d['df1_id'] = df1_row['PRODUCT_ID']
            ...
    df3 = pd.DataFrame.from_dict(d)
    

提交回复
热议问题