假设我有一个数据中心:
Sentences Group
It is you 0
She likes flower 1
She hates gardening 2以及一份停车名单:
from nltk.corpus import stopwords
stop_words = stopwords.words('english')如果列df['Sentences']中的所有标记/单词都包含stop_words列表中的任何标记/单词,如何删除行。因此,我的结果应该是这样的:
Sentences Group
She likes flower 1
She hates gardening 2发布于 2020-03-23 09:31:10
可以用空格分隔列,然后比较列表:
df = df[~df['Sentences'].apply(lambda r: list(set(r.split(' ')).intersection(stop_words))!=[] )]~的意思是“不包含”以下行。
发布于 2020-03-23 09:58:54
这是我的解决方案:
filtered_df = df[~df['Sentences'].str.split().apply(lambda x: any(s for s in x if s in stop_words))]先分句。然后检查句子中的任何单词是否也在你的stop_words中。如果其中有一个单词,any将返回True。我们用~来逆转这一点。
https://stackoverflow.com/questions/60810645
复制相似问题