Python 3.x 将结果附加到现有excel中,而不是用Python编写新的csv文件

Python 3.x 将结果附加到现有excel中,而不是用Python编写新的csv文件,python-3.x,pandas,dataframe,pandas.excelwriter,Python 3.x,Pandas,Dataframe,Pandas.excelwriter,我已使用以下代码将df1写入excel文件的Sheet1: writer = pd.ExcelWriter('data-{}.xlsx'.format(pd.datetime.today().strftime('%Y%m%d-%H%M%S'))) df1.to_excel(writer, 'Sheet1', index = False) #df2.to_excel(writer,'Sheet2', index = False) writer.save() projects = df['na

我已使用以下代码将
df1
写入excel文件的
Sheet1

writer = pd.ExcelWriter('data-{}.xlsx'.format(pd.datetime.today().strftime('%Y%m%d-%H%M%S'))) 
df1.to_excel(writer, 'Sheet1', index = False)
#df2.to_excel(writer,'Sheet2', index = False) 
writer.save()
projects = df['name'].unique().tolist()

processedProjects = []
matchers = []

threshold_ratio = 60

for project in projects:
    if project:
        processedProject = fuzz._process_and_sort(project, True, True)
        processedProjects.append(processedProject)
        matchers.append(fuzz.SequenceMatcher(None, processedProject))

today_string = datetime.today().strftime('%Y%m%d-%H%M%S')

with open('data-' + today_string + '.csv', 'w') as f1:
    writer = csv.writer(f1, delimiter = ',', lineterminator = '\n', )
    writer.writerow(('name', 'name_', 'ratio'))

    for project1, project2 in itertools.combinations(enumerate(processedProjects), 2):
        matcher = matchers[project1[0]]
        matcher.set_seq2(project2[1])
        ratio = int(round(100 * matcher.ratio()))
        if ratio >= threshold_ratio:
            #print(projects[project1[0]], projects[project2[0]])
            my_list = projects[project1[0]], projects[project2[0]], ratio
            print(my_list)
            writer.writerow(my_list)
我还使用以下代码创建了一个新的dataframe:

writer = pd.ExcelWriter('data-{}.xlsx'.format(pd.datetime.today().strftime('%Y%m%d-%H%M%S'))) 
df1.to_excel(writer, 'Sheet1', index = False)
#df2.to_excel(writer,'Sheet2', index = False) 
writer.save()
projects = df['name'].unique().tolist()

processedProjects = []
matchers = []

threshold_ratio = 60

for project in projects:
    if project:
        processedProject = fuzz._process_and_sort(project, True, True)
        processedProjects.append(processedProject)
        matchers.append(fuzz.SequenceMatcher(None, processedProject))

today_string = datetime.today().strftime('%Y%m%d-%H%M%S')

with open('data-' + today_string + '.csv', 'w') as f1:
    writer = csv.writer(f1, delimiter = ',', lineterminator = '\n', )
    writer.writerow(('name', 'name_', 'ratio'))

    for project1, project2 in itertools.combinations(enumerate(processedProjects), 2):
        matcher = matchers[project1[0]]
        matcher.set_seq2(project2[1])
        ratio = int(round(100 * matcher.ratio()))
        if ratio >= threshold_ratio:
            #print(projects[project1[0]], projects[project2[0]])
            my_list = projects[project1[0]], projects[project2[0]], ratio
            print(my_list)
            writer.writerow(my_list)
如何将
Sheet2
附加到
data-{}.xlsx
中,而不是编写名为
'data-'+today.\u string+'.csv'
的csv文件

提前谢谢你的帮助