我有以下代码,将数据从csv文件复制并粘贴到excel文件(它比较员工的姓名并复制日期)。唯一的问题是它只复制精确匹配的日期(William对William,而不是Will to William)。有没有使用fuzzyfuzzy使它也从近似匹配中复制数据。代码如下所示。在
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
import csv
import openpyxl
import datetime
training_updates = {};
with open('from.csv') as frombook:
reader = csv.DictReader(frombook)
for row in reader:
if int(row["ViewTotalScore"]) > 70:
training_updates[(row["ViewerInfo"].strip("[]").lower())] = (row["DateTime"])[:-8].rstrip()
wb = openpyxl.load_workbook('to.xlsm', data_only=True, keep_vba=True)
wb2 = openpyxl.load_workbook('to.xlsm', keep_vba=True)
sheetcheck = wb.get_sheet_by_name(wb.get_sheet_names()[0])
sheetwrite = wb2.get_sheet_by_name(wb2.get_sheet_names()[0])
for rowNum in range(2, sheetcheck.max_row):
if sheetcheck.cell(row=rowNum, column=3).value is not None:
employee = str(sheetcheck.cell(row=rowNum, column=3).value).lower()
if employee in training_updates:
xldate = datetime.datetime.strptime(training_updates[employee], "%Y-%m-%d").strftime("%m/%d/%Y")
sheetwrite.cell(row=rowNum, column=5).value = xldate
print("Updated record for " + employee)
wb2.save('updatedto.xlsm')
我也曾使用fuzzyfuzzy extractOne来尝试拉取它们,但是对于fuzzy匹配没有任何结果:
^{pr2}$
我能够接近我想要做的事情:
相关问题 更多 >
编程相关推荐