python - 如何在 python 中使用 vlook up 在数据框中查找文本?
解决方案
我可以重新创建检查一个列表与另一个列表的结果。您的匹配标准是什么不是很清楚或合乎逻辑。“john usa”是与“aviation john”的成功匹配,因为两者都出现了“john”。但是“john usa”是否会与“usa mark sas”构成匹配,因为“usa”同时出现在两者中?连字符、逗号等呢?如果这被清除了会有所帮助。
无论如何,我希望以下内容会有所帮助,祝你好运:-
#create two lists of tuples based on the existing dataframes.
check_list = list(df_check.to_records(index=False))
full_list = list(df_full.to_records(index=False))
#create a set - entries in a set are unique
results=set()
for check in check_list: #for each record to check...
for search_word in check[0].split(" "): #take the first column and split it into its words using space as a delimiter
found=any(search_word in rec[0] for rec in full_list) #is the word a substring of any of the records in full list? True or False
results.add((check[0], found)) #add the record we checked to the set with the result (the set avoids duplicate entries)
#build a dataframe based on the results
df_results=df(results, columns=["check", "found"])
推荐阅读
- python-3.x - 使用 python3 请求模块对詹金斯进行身份验证
- ruby - 试图用 Watir 按 CRTL+T
- android - 在画布上绘图计算位置错误
- visual-studio-code - 查看/调试慢速保存参与者
- date-range - 如何解决两个日期字段和多个案例的问题
- vue.js - 检查用户是否是管理员 vue 路由器和 vuex
- javascript - 如何使用反应和样式组件制作手风琴菜单
- anylogic - 通过计划定义运输车队容量会大大减慢模拟运行速度
- grouping - 如何使用 FLOWR 和 XQuery 创建新的列表项?
- apache-samza - 强制 RocksDB 支持的 Samza 键/值存储从 kafka 更改日志重新加载?