python - 运行 Fuzzywuzzy 字符串匹配器脚本的问题
问题描述
该脚本应该从测试文件中获取字符串并将它们与主文件进行比较,并将匹配结果作为输出文件中的结果。
我遇到的问题是运行它不会产生所述输出文件。
# -*- coding: utf-8 -*-
"""
Test - String matching
"""
#%%
from fuzzywuzzy import process
import pandas as pd
import os
#%%
def StringMatch (master, testfile, num_match=3):
master_names = master.iloc[:,3]
test_names = testfile.iloc[:,0]
fhp_new = [process.extract(x, master_names, limit=limit) for x in test_names]
lab=" "
i=1
while i<=num_match:
lab = lab + " " + "Match" + str(i)
i = i+1
aggregated_matches = pd.DataFrame(fhp_new, columns = lab.split())
d={}
for x in range (1, num_match + 1):
d["Match{0}".format(x)] = [y[0] for y in aggregated_matches["Match" + str(x)]]
d["test_original"] = test_names
d["perfect match"] = d["Match1"] == d["test_original"]
out = pd.DataFrame(data=d)
out.to_csv(str(outFile + ".csv"))
return (out)
print ("finished")
master = pd.read_csv("MasterVendorDevice.csv")
testfile = pd.read_csv("testfile.csv", encoding='latin-1')
limit=3
baseDir = os.path.join("/Users", "Tim", "Desktop", "String Matcher")
outDir = os.path.join(baseDir, "out")
if not os.path.exists(outDir):
os.makedirs(outDir)
outFile = os.path.join(outDir, "matches")
解决方案
推荐阅读
- javascript - React/React-Hooks:需要在 React Hooks 组件中运行 onLoad 函数
- angular - 故事书中的RouterLink?
- c# - 无法在 DbSet 测试替身上调用 AddRange
- ios - 在 Firebase 测试实验室测试 APNS
- vb.net - 如何使用 VB.net 下载 YouTube 视频
- google-apps-script - OnChange 在某些工作表中更改时触发,而不是在工作簿的任何工作表中
- facebook - 如何将标题和描述等信息添加到帖子中的链接
- ios - 如何在数据库中保存 Apple 应用内购买的收据?
- c# - 尝试序列化异常时忽略自定义解析器
- reactjs - 截取全日历时间网格视图的正确方法