有关于匹配数据的问题。我有两个excel文件,一个在数据库的摘录中,它偶尔更新一次,不保存所有记录,因为它没有链接到存储信息的源应用程序。
我得到的另一个摘录是一个系统的摘录,每个人都会输入信息。
这两个excel文件有大量的id号。我的老师让我对数据进行匹配,这样我就可以看到哪些数据丢失了。他让我用v--向上看,但这没有道理。是否有更简单的方法来匹配两个excel工作表中的数据?
谢谢你提前给我时间。
发布于 2022-07-25 06:39:08
我建议将pandas
库与concat一起使用。
import glob
import pandas as pd
# specifying the path to excel files
path = "C:/downloads"
# excel files in the path
file_list = glob.glob(path + "/*.xlsx")
# list of excel files we want to merge.
# pd.read_excel(file_path) reads the
# excel data into pandas dataframe.
excl_list = []
for file in file_list:
excl_list.append(pd.read_excel(file))
# concatenate all DataFrames in the list
# into a single DataFrame, returns new
# DataFrame.
excl_merged = pd.concat(excl_list, ignore_index=True)
# exports the dataframe into excel file
# with specified name.
excl_merged.to_excel('merged_excel.xlsx', index=False)
一旦打开了两个不同的文件( pd.merge()
),您也可以使用df1 = pd.read_excel(file1); df2 = pd.read_excel(file2)
将它们合并到特定的列名上,在您的情况下可能是id
。df1.merge(df2, left_on='lkey', right_on='rkey')
根据文件添加后缀。
https://stackoverflow.com/questions/73110806
复制相似问题