Lets say I have a data frame lets call it A
Key_Word | Code |
---|---|
Market | A1 |
Theater | A2 |
And I have another Data Frame lets call it B
Sentence | Components from A |
---|---|
John went to the theater | |
Mary went to the Market and then the theater |
I would like to find a way to dynamically update dataframe B such that it loops through each b.sentence, and record the A.Code if it finds an instance of the A.Key_word.If a keyword appears more than once in A, I would like it to appear only once in B.Components_from_A. If multiple keywords appear I would like it to be recorded as Code1+Code2+Code3…..
Sentence | Components_from_A |
---|---|
John went to the theater | A2 |
Mary went to the Market and then the theater | A1+A2 |
Jack decided to go to the theater now as opposed to going to the theater later | A2 |
Im assuming that I could build off something like
import pandas as pd
import numpy as np
A=pd.read_csv('A.csv')
B=pd.read_csv('B.csv')
Dict=dict(zip(A.Key_Word,A.Code))
What im struggling with would be dynamically updating the column in B and the logic I would need to do it in the way I described
Thomas Short is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.