Skip to content
Advertisement

Merge Pandas Dataframes based on substring or partial match in another Dataframe

I have two sample data frames:

JavaScript

Using this will result result in an empty dataframe.

JavaScript

How could I go about using a merge to use a substring / partial match from df2['Group_Var'] in df1['Model']? Perhaps using the str.contains() method as part of the merge?

Just for context my expected output would be something like this:

JavaScript

Advertisement

Answer

Use pd.concat with axis=1:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement