python - Pandas, join row from target file based on condition -


i need merge row target dataframe source dataframe on fuzzy matching condition has been developed, let's call method fuzzytest. if fuzzy test returns true, want merge row target file source file when matched.

so left join target company passes fuzzytest when compared source company.

source dataframe

          source company 0           cool company 1              bigpharma 2            tod kompany 3               wallmart 

target dataframe

                       target company 0                        kool company 1                           big farma 2                      todd's company 3                              c-mart 4                           supermart 5                          smallstore 6                             shoprus 

hopefully after mapping through fuzzytest output be:

                       source company       target company 0                        cool company         kool company 1                           bigpharma            big farma 2                         tod kompany       todd's company 3                            wallmart                  nan      

so if fuzzy logic compare 2 strings on each row, wrap function takes in column source , column target. make both columns in 1 dataframe run:

def fuzzytest(source,target):     .....     if ...:       return target     else:       return none  df['target company'] = df.apply(lambda x: fuzzytest(x['source'],x['target']) 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -