I have a dataframe containing platform terms (platform + 3 words before):
| Paper A | Paper B |
|---|---|
| at a digital platform | add a digital platform |
| change the consumer platform | got a feedback platform |
For each string in the dataframe I want to delete the stopwords and any word that is occuring in front of the stop word.
Dataframe should look like this:
| Paper A | Paper B |
|---|---|
| digital platform | digital platform |
| consumer platform | feedback platform |
My best try so far:
import regex as re
def remove_stops_and_words_before(doc):
stopwords = re.compile(r"\L<words>", words=['n‘t', 'during', 'from', 'elsewhere', 'herself', 'anyone',...]
rx_to_last = r'^.*{}'.format(re.escape(stopwords))
doc = re.sub(rx_to_last, '', doc, flags=re.DOTALL).strip()
return doc
df_new = df.applymap(remove_stops_and_words_before)