【发布时间】:2020-04-24 10:15:11
【问题描述】:
我有一列数据如下所示:
import pandas as pd
import numpy as np
Items
0 Product A + Product B + Product C
1 Product A + Product B + Product B1 + Product C1
2
我想查看这些项目并找出该列是否包含一些特定项目,这些项目与我有兴趣标记为包含在项目列中的产品有关:
My_Items = ['Product B', 'Product C', 'Product C1']
我已经尝试了以下 lambda 函数,但如果列中的产品超过 1 个,它不会拾取我正在搜索的字符串:
df['My Items'] = df['Items'].apply(lambda x: 'Contains my items' if x in My_Items else '')
有谁知道如何在 lambda 函数的列表中搜索多个字符串?
感谢您的任何帮助或建议。
亲切的问候
【问题讨论】:
-
预期输出是什么?
标签: python string pandas lambda