У меня есть два Pandas кадра данных, один содержит пары ключевых слов, а другой содержит заголовки. Я хочу присоединить левый фрейм данных к фрейму данных пар ключевых слов, если заголовок содержит пару ключевых слов.
Заголовки могут содержать несколько пар ключевых слов, и в каждом заголовке может быть несколько пар ключевых слов. Есть ли способ сделать это?
Пример пары ключевых слов df:
import pandas as pd
pd.DataFrame({'keywords_combined': {0: 'gmo pesticide', 1: 'oil gas', 2: 'renewable energy', 3: 'eco friendly', 4: 'clean energy', 5: 'green new', 6: 'new deal', 7: 'climate change'}, 'keyword_difficulty_as_number': {0: 1, 1: 3, 2: 2, 3: 1, 4: 2, 5: 2, 6: 2, 7: 2}})
Пример названий df:
import pandas as pd
pd.DataFrame({'title': {0: 'democrat alexandria ocasio cortez provides an eco friendly green new deal', 1: ' the social with the environment has to go hand in hand for effective climate change dechel mckillian founder of galerie la', 2: 'making sustainable fashion more effective for climate change', 3: 'organic clothing the needs wants of consumers survey on sustainable fashion', 4: 'renewable energy capacity set for 50 growth over next few years iea says eco planet news', 5: 'energy transition needs staged approach to aemo clean energy eco planet news', 6: 'the short list of climate change actions that will work and more on the green new deal', 7: 'the top 5 tools for sustainable fashion shopping this fall', 8: 'article in danish about maersk narrowing down their choice of future shipping fuel for clean energy to three choices alcohols biogas and ammonia', 9: 'rome summit takes bold step toward agroecology'}, 'votes': {0: 8, 1: 12, 2: 14, 3: 1, 4: 28, 5: 5, 6: 24, 7: 0, 8: 3, 9: 15}})
Желаемый результат:
![enter image description here](https://i.stack.imgur.com/p8Z8g.png)
Сначала я попытался использовать df.merge, временно изменив имя столбца title заголовка второго информационного кадра на «Keywords_combined», однако «on», похоже, не работает с чем-то вроде str.contains:
df = df.merge(df2, on='keywords_combined', how='left')
Любая помощь будет очень признателен, спасибо.