这是使用个人的可读解决方案
search_func:
def search_func(row): matches = [test_value in row["Description"].lower() for test_value in row["Text_Search"]] if any(matches): return "Yes" else: return "No"
然后按行应用此函数:
# create example datadf = pd.Dataframe({"Description": ["CANSEL SURVEY E PAY", "JX154 TFR?FR xxx8690"], "Employer": ["Cansel Survey Equipment", "Cansel Survey Equipment"]})print(df) Description Employer0 CANSEL SURVEY E PAY Cansel Survey Equipment1 JX154 TFR?FR xxx8690 Cansel Survey Equipment# create text searches and match columndf["Text_Search"] = df["Employer"].str.lower().str.split()df["Match"] = df.apply(search_func, axis=1)# show resultprint(df) Description Employer Text_Search Match0 CANSEL SURVEY E PAY Cansel Survey Equipment [cansel, survey, equipment] Yes1 JX154 TFR?FR xxx8690 Cansel Survey Equipment [cansel, survey, equipment] No
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)