【发布时间】:2020-04-01 09:29:07
【问题描述】:
我有两张 Excel 表格,正在构建一个小程序来比较这些表格中的两列以找出差异。问题是,由于这些输入大部分是手动完成的,因此存在很多拼写错误,应该忽略。该程序应突出显示新的或已删除的数据。
我正在阅读有关模糊文本的内容,我在网上找到了这段代码 (link),但它的输出只是生成了一个包含完全相同条目的 CSV(不是我想要的)。我仍然会在此处添加它,以便您知道我在说什么。
from __future__ import division
import numpy as np
import pandas as pd
from collections import Counter
import collections
from fuzzywuzzy import fuzz
import time
from two_lists_similarity import Calculate_Similarity as cs
#the first file
book_old = pd.read_excel(r' #Input file here', sheet_name = '#Sheet Name Here')
data_old = book_old.iloc[7:,2].tolist()
#Selecting the column i want to compare
#second file to compare with
book_new = pd.read_excel(r'#source here', sheet_name = '#Sheet name')
data_new = book_new.iloc[7:,2].tolist() #selecting col
inp_list = data_old
ref_list = data_new
#this is what i picked up online because i couldnt do myself
#the plan is to iterate the list and find entries that are different, ignore spellings
# Create an instance of the class. This is otherwise called as an object
csObj = cs(inp_list,ref_list)
# csObj is now the object of Calculate Similarity class.
csObj.fuzzy_match_output(output_csv_name = 'pkg_sim_test_vsc.csv', output_csv_path = r'#Output path')
【问题讨论】:
-
您正试图告诉计算机判断一个单词是否与另一个拼写错误的单词相同?这非常困难,如果从技术上讲,它们是不同的,如何知道单词是否相同?
-
我在考虑设置一个最小比例?就像当相似度大于 75% 时,我们认为这只是一个拼写错误而不是一个全新的单词。如果我们想让它们尽可能低,显然会有误报。
标签: python python-3.x list fuzzy-comparison