Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用RecordLink进行python字符串匹配-可以为特定情况编写规则_Python_Pandas_Record_String Matching_Record Linkage - Fatal编程技术网

使用RecordLink进行python字符串匹配-可以为特定情况编写规则

使用RecordLink进行python字符串匹配-可以为特定情况编写规则,python,pandas,record,string-matching,record-linkage,Python,Pandas,Record,String Matching,Record Linkage,我正在使用python的RecordLink工具包来字符串匹配来自两个dataframes,df1和df2的学校名称列,同时阻塞它们的公共列'division' 我的代码如下: import recordlinkage from recordlinkage.standardise import clean indexer = recordlinkage.Index() indexer.block('division') candidate_links_2 = indexer.index(df1

我正在使用python的
RecordLink
工具包来字符串匹配来自两个
dataframes
df1
df2
的学校名称列,同时阻塞它们的公共列
'division'

我的代码如下:

import recordlinkage
from recordlinkage.standardise import clean

indexer = recordlinkage.Index()
indexer.block('division')
candidate_links_2 = indexer.index(df1, df2)
compare = recordlinkage.Compare()
compare.string('school_name', 'school_name', method='jaro', threshold=0.95)
compare_vectors_2 = compare.compute(candidate_links_2, df1, df2)

matches_2 = compare_vectors_2[compare_vectors_2[0]==1.0]
matches_2.reset_index(inplace=True) 
matches_2 = matches_2.rename(columns={'level_0': 'df1_index', 'level_1': 'df2_index', 0: 'match'})

matches_duplicates_dropped_2 = matches_2.drop_duplicates(subset = ['df1_index'], keep = 'last') 
matches_duplicates_dropped_2
有了这段代码,我得到了一些不应该匹配的匹配项-

    df1_index   df2_index   match   df1_school  df2_school
2   15136   26636   1.0 girls middle 34sp   girls middle 53sp
4   15137   26636   1.0 girls middle 34sp   girls middle 53sp
7   15148   26636   1.0 girls middle 35sp   girls middle 53sp
10  15149   26636   1.0 girls middle 35sp   girls middle 53sp
... ... ... ... ... ...
43794   64087   6601    1.0 islamabad model i v2 i 91ii islamabad model i v2 i 101ii

我想创建一个单独的规则,如果学校名称中有数字,例如
'girls middle 35sp'
有数字
35
等,那么数字必须是'exact match',因此
'girls middle 35sp'
只能与
'girls middle 35sp'匹配,而不应该与
等“女孩中53分”匹配


我想知道这是否有可能,或者是否有更好的工具包用于此特定目的。

您应该尝试threshold=1

从:

阈值(浮点,浮点元组)–阈值。高于或等于此阈值的所有近似字符串比较值均为1。否则为0


然后,其他相同的学校名称将无法匹配,例如“伊斯兰堡女子小学”和“伊斯兰堡女子小学”(它们是同一所学校,其中一所学校的拼写错误很小)