![](/img/trans.png)
[英]Python, how to combine different excel workbooks into one excel workbook as sheets
[英]How to merge multiple excel sheet with the same name from different workbooks and save into a new excel workbook using Python
在合并多个工作簿中具有相同工作表名称的 excel 文件并将其保存在新工作簿中时需要一些帮助。
import pandas as pd
import glob
import os
path = "C:/Users/"
fname = glob.glob(path + "\*.xlsx")
print(fname)
mfile = pd.DataFrame()
result_DFs = []
for i in fname:
df = pd.read_excel(i,sheet_name = None)
for sheet in df:
if (sheet == "Owner and Status each sheet"):
result = result_DFs.append(df[sheet])
在此之后我被困住了。 有人能帮我吗?
下面的代码将append来自给定路径中存在的所有工作簿的选项卡名称“每个工作表的所有者和状态”中的 result_DFs 中的数据;
import pandas as pd
import glob
path = r"C:\Users"
fname = glob.glob(path + "\*.xlsx")
result_DFs = pd.DataFrame()
for i in fname:
try:
df = pd.read_excel(i,sheet_name = "Owner and Status each sheet")
result_DFs = pd.concat([result_DFs,df])
except:
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.