你可以用
extract与
join在所有值
List通过
|什么手段
or在
regex:
List1 = ['Three has' , 'Mail' , 'Done' , 'Game' , 'Time has come']df['Col 3'] = df['Col 2'].str.extract("(" + "|".join(List1) +")", expand=False)print (df) Col 1Col 2 Col 30 1 The date NaN1 2 Three has come Three has2 3 Mail Sent Mail3 4 Done Deal Done另一个解决方案:
List1 = ['Three has' , 'Mail' , 'Done' , 'Game' , 'Time has come']df['Col 3'] = df['Col 2'].apply(lambda x: ''.join([L for L in List1 if L in x]))df['Col 3'] = df['Col 3'].mask(df['Col 3'] == '')print (df) Col 1Col 2 Col 30 1 The date NaN1 2 Three has come Three has2 3 Mail Sent Mail3 4 Done Deal Done



