3 回答
TA贡献1827条经验 获得超8个赞
试试这个,看看它是否涵盖了您的用例:使用itertools 的产品和基于条件的过滤器获取两列的交叉笛卡尔:
from itertools import product
m = [ left for left, right
in product(df.Note,df1.Code_Number)
if str(right) in left]
pd.DataFrame(m,columns=['Note'])
Note
0 The code to this is 1003
TA贡献1820条经验 获得超10个赞
做这个:
df_1.loc[df_1['Note'].apply(lambda x: any(str(number) in x for number in df_2['Code_Number']))]
TA贡献1835条经验 获得超7个赞
Firstly, you have to create 1 column in your df1 where the notes are with a list of numbers that are present in the Notes and then Compare the List column of numbers with the List column of the df2 where the numbers are present(both should be in list format)
#Extract Numbers from Notes
a_string = "0abcadda1 11 def 23 10007"
numbers = [int(word) for word in a_string.split() if word.isdigit()]
print(numbers)
list_test = "103,23"
#Finding common element from both lists the list
L1 = [2,3,4]
L2 = [1,2]
[i for i in L1 if i in L2]
S1 = set(L1)
S2 = set(L2)
print(S1.intersection(S2))
#If you want to find out the common element
def common_data(list1, list2):
result = False
# traverse in the 1st list
for x in list1:
# traverse in the 2nd list
for y in list2:
# if one common
if x == y:
result = True
return result
return result
# driver code
a = [1, 2, 3, 4, 5]
b = [5, 6, 7, 8, 9]
print(common_data(a, b))
a = [1, 2, 3, 4, 5]
b = [6, 7, 8, 9]
print(common_data(a, b))
添加回答
举报