I have 2 dataframes across which I need to map the keywords. The input data(df1) looks like this:
keyword subtopic
post office Brand
uspshelp uspshelp Help
package delivery Shipping
fed ex Brand
ups fedex Brand
delivery done Shipping
united states location
rt ups retweet
This is the other dataframe (df2) which is to be used for keyword matching:
Key Media_type cleaned_text
910040 facebook will take post office
409535 twitter need help with upshelp upshelp
218658 facebook there no section post office alabama ups fedex
218658 facebook there no section post office alabama ups fedex
518903 twitter cant wait see exactly ups fedex truck package
2423281 twitter fed ex messed seedless
763587 twitter crazy package delivery rammed car
827572 twitter formatting idead delivery done
2404106 facebook supoused mexico united states america
1077739 twitter rt ups
I want to map the 'keyword' column in df1 to the 'cleaned_text' column in df2 based on few conditions:
- One row in 'keyword' can be mapped to more than one row in 'cleaned_text' (One to many relationship)
- It should select the whole keyword together and not just individual words.
- If a 'keyword' matches to more than one row in 'cleaned_Text' it should create new records in the output dataframe(df3)
This is how the output dataframe(df3) should look like:
Key Media_type cleaned_text keyword subtopic
910040 facebook will take post office post office Brand
409535 twitter need help with upshelp upshelp uspshelp uspshelp Help
218658 facebook there no section post office alabama ups fedex post office Brand
218658 facebook there no section post office alabama ups fedex ups fedex Brand
518903 twitter cant wait see exactly ups fedex truck package ups fedex Brand
2423281 twitter fed ex messed seedless fed ex messed Brand
763587 twitter crazy package delivery rammed car package delivery Shipping
827572 twitter formatting idead delivery done delivery done Shipping
2404106 facebook supoused mexico united states america united states america location
1077739 twitter rt ups rt ups retweet