I have a dataframe with multiple columns containing phrases. What I would like to do is
- identify the column (per row observation) that contains a string that exists within a pre-made list of words.
- With this information, create a new variable in this dataframe that contains the value in the column that matched with the list. (In this example, "lst" is my list of words)
For example: Starting Dataframe:
And I would like to end up with this:
New_var is the new variable, and it selected the response in col1 of observation 1 because the "apple" in apple sauce matched with the "apple" in the list. Big oranges would appear for Observation 2 because it matched with "oranges" from the list.
I have tried doing this with list comprehension from this link: List Comprehension, but remain unsuccessful. I wish to do this in python. Any suggestions? I am relatively new to this programming language.
Thank you very much. If I have posted inappropriately or the answer exists somewhere I have not found it, I appreciate any guidance in the right direction.