My question is somewhat similar to this one: How to merge pandas on string contains?, but I need a different output and the problem itself is a bit more complex. So I have 2 dataframes similar to the ones below:
df1 = pd.DataFrame({'ref_name':['city-louisville','city-louisville','city-louisville', 'town-lexington','town-lexington','town-lexington'], 'un_name1':['CPU1','CPU2','GPU1','CPU1','CPU2','GPU1'], 'value1':[10,15,28,12,14,14]})
df2 = pd.DataFrame({'ref_name':['louisville','louisville','lexington','lexington'], 'un_name2':['CPU','GPU','CPU','GPU'], 'value2':[25,28,26,14]})
I need to join based on ref_name
and un_name
based on the substrings within them. They won't always be as clean as this, but I figured it made for a decent little example. So my desired output in this case would look something like this:
ref_name | un_name1 | un_name2 | value1 | value2
---------------------------------------------------------
louisville| CPU1 | CPU | 10 | 25
louisville| CPU2 | CPU | 15 | 25
louisville| GPU1 | GPU | 28 | 28
lexington | CPU1 | CPU | 12 | 26
lexington | CPU2 | CPU | 14 | 26
lexington | GPU1 | GPU | 14 | 14
Thanks in advance for any help on this!