【发布时间】:2020-01-24 01:34:50
【问题描述】:
Python,如何在第二个 list2 中搜索 list1 中的项目并返回具有相同项目的数据框。
任何人都会提供帮助,我需要找出两个字符串中的 some 值,然后返回与该行相关的 id。
按照我如何尝试在另一个数据帧中返回相等的值失败。
这是参考列表1(binglist)
binglist
['31664745', '283494006', '283494005', '283494009', '283494007',
'283494008','283703957', '283703955', '283703956', '283703954',
'283703960', '31454872', '283536236', '0', '0', '0', '0', '0',
'0', '0', '0']
这是我们需要搜索的列表,list2 (Data-frame)
cw["campaignname"].unique()
cw["campaignname"]
array(['35119190', '31664745', '4899110', '804530544', '325772660',
'283494005', '64002140', '272351300', '2016404066', '753857250',
'6.12855E+12', '283703956', '283703960',
'169278078', 'business', '636589579', '52106838', 'science',
'820812876', 'art'], dtype=object)
按照我如何尝试在另一个数据帧中返回相等的值失败。
# using a set makes the later `x in keep` test faster
keep= set(binglist)
# -> Loop all cw["campaignname"] records only(Bing records)
# -> If there is a equal value
# -> return the id
b = [x= cw["id"] for x in cw["campaignname"].filter(["Bing", "BingBrand", "BingNonBrand"]) if x in bing]
# it give me empty result
它给了我空的结果
【问题讨论】:
-
预期结果是什么?
-
相等的字符串。赞35119190
标签: python string pandas hash string-search