Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.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
Python 将dataframe中一项的函数应用于所有其他项_Python_Text Mining_Sentence Similarity - Fatal编程技术网

Python 将dataframe中一项的函数应用于所有其他项

Python 将dataframe中一项的函数应用于所有其他项,python,text-mining,sentence-similarity,Python,Text Mining,Sentence Similarity,我正在检查Python中文本的相似性。我有大约100条记录的数据集,并准备了一个用于检查相似性的函数——它有两个参数,用于两组单词 def getSimilarity(a, b): x = set(a) y = set(b) z = x.intersection(y) return float(len(z)) / (len(x) + len(y) - len(z)) 我的数据帧: 1 ['a','b','c','d'] other columns 2 ['a'

我正在检查Python中文本的相似性。我有大约100条记录的数据集,并准备了一个用于检查相似性的函数——它有两个参数,用于两组单词

def getSimilarity(a, b):
    x = set(a)
    y = set(b)
    z = x.intersection(y)
    return float(len(z)) / (len(x) + len(y) - len(z))
我的数据帧:

1 ['a','b','c','d']  other columns
2 ['a','h','e','f']  other columns
3 ['3','b','c','g']  other columns
4 ['y','b','c','z']  other columns
5 ['h','b','j','k']  other columns

我想创建一个方法,该方法将对给定行的数据帧进行迭代,并找出两条最相似的记录。
例如,数据帧中索引1的
checkSimilarity(1)
checkSimilarity(df['col'][1])
将给我们提供最相似的
[3,4]

到目前为止您尝试了什么?您可以使用
numpy
矢量化: