python自动excel查询系统

2024-04-20 09:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道这是很多代码,有很多事情要做,但我真的卡住了,不知道如何继续后,我得到的功能,该程序可以匹配相同的文件。我很肯定你知道如何从excel查找工作。这个程序基本上也是这样。我试着评论出重要的部分,希望你能给我一些帮助,我可以继续这个项目。非常感谢

import pandas as pd
import xlrd

File1 = pd.read_excel("Excel_test.xlsx", usecols=[0], header=None, index=False) #the two excel files with the columns that should be compared
File2 = pd.read_excel("Excel_test02.xlsx", usecols=[0], header=None, index=False)

fullFile1 = pd.read_excel("Excel_test.xlsx", header=None, index=False)#the full excel files 
fullFile2 = pd.read_excel("Excel_test02.xlsx",  header=None, index=False)


i = 0

writer = pd.ExcelWriter("output.xlsx")

def loadingTime(): #just a loader that shows the percentage of the matching process
    global i
    loading = (i / len(File1)) * 100
    loading = round(loading, 2)
    print(str(loading) + "%/100%")

def matcher():
    global i
    while(i < len(File1)):#goes in column that should be compared and goes on higher if there is a match found in second file
        for o in range(len(File2)):#runs through the column in second file
            matching = File1.iloc[i].str.lower() == File2.iloc[o].str.lower() #matches the column contents of the two files
            if matching.bool() == True:
                print("Match")
                """
                df.append(File1.iloc[i])#the whole row of the matched column should be appended in Dataframe with the arrangement of excel file
                df.append(File2.iloc[o])#the whole row of the matched column should be appended in Dataframe with the arrangement of excel file
                """
        i += 1

matcher()

df.to_excel(writer, "Sheet")
writer.save() #After the two files have been compared to each other, now a file containing both excel contents and is also arranged correctly

Tags: oftheinnonefalsereadindexcolumn