如何使用 python 中的 pandas 将多个关键字与数据框列值映射

How to map sevaral keywords with a dataframe column values using pandas in python

你好,我有一个关键字列表。

keyword_list=['one','two']

DF,

    Name      Description
    Sri       Sri is one of the good singer in this two
    Ram       Ram is one of the good cricket player

我想找到包含我 keyword_list 中所有值的行。

我想要的输出是,

output_Df,
    Name    Description
    Sri     Sri is one of the good singer in this two

I tried, mask=DF['Description'].str.contains() method but I can do this only for a single word pls help.

使用 list comprehension 创建的所有掩码中的 np.logical_and + reduce

keyword_list=['one','two']

m = np.logical_and.reduce([df['Description'].str.contains(x) for x in keyword_list])
df1 = df[m]
print (df1)

  Name                                Description
0  Sri  Sri is one of the good singer in this two

面膜的替代品:

m = np.all([df['Description'].str.contains(x) for x in keyword_list], axis=0)

#if no NaNs
m = [set(x.split()) >= set(keyword_list) for x in df['Description']]