2024-09-29 21:24:52 发布
网友
我有一个包含两列的dataframe,其中两列是Artist_x和{}。我想找出这两个列之间的相似性,并得到作为新列的相似性百分比。我想我可以使用difflib,但不确定具体如何使用。在
Artist_x
我目前有:
mergednew['SimilarityArtist'] = mergednew.apply(lambda row: similar(row['Artist_x'], row['Artist_y']), axis=1)
您可以尝试以下代码:
from sklearn.metrics.pairwise import cosine_similarity Artist_x=Artist_x.reshape(1,-1) Artist_y=Artist_y.reshape(1,-1) cosine_similarity(Artist_x,Artist_y)
您将得到一些介于0到1之间的值。1表示最大相似度,0表示最小相似度。在
你是想找到完全匹配还是部分匹配?在
可以使用以下方法找到精确匹配:
num_matches = [] total_items = len(column_A) for i in range(len (column_A)): if column_A == column_B: num_matches.append (1) print(num_matches/total_items)
您可以尝试以下代码:
您将得到一些介于0到1之间的值。1表示最大相似度,0表示最小相似度。在
你是想找到完全匹配还是部分匹配?在
可以使用以下方法找到精确匹配:
相关问题 更多 >
编程相关推荐