I'm a graduate student and working wit python to prepare my data set for my research. I'm not that confident with the use of python, so I would really appreciate your Help.
Continuing on a previous asked question (how to do re.compile() with a list in python)
I would like to apply this kind of word recognition one column in a dataframe.
import pandas as pd
from itertools import compress
fruits = ['apple', 'banana', 'cherry']
df = pd.DataFrame({"a":['green apple and red cherry', 'blue', 'apple, banana and cherry', 'banana banana split'],"b":[0,2,0,1]},
index = [1,2,3,4])
# Create a list to store the data
grades = []
grades = list(compress(fruits, (f in df.a for f in fruits)))
df['grades'] = pd.Series(grades)
This doesn't work out, since a data frame is generated where all 'grade-values' are NaN.
Additionally, I would like to know if this is also possible with a list of sentences, instead of a list of words. And how this could be done.
Thank you in advance!