如何自动合并上百个结构相同的Excel表格
使用 pandas 库的 glob 模块配合 pd.concat() 函数可以高效完成此任务。通过通配符获取所有文件路径,遍历读取为 dataframe 后直接拼接,最后导出为一个新文件。

如何处理合并过程中的索引冲突与内存溢出
在合并大量数据时,默认索引会导致重复或覆盖,需设置 ignore_index=True;若文件过大导致内存不足,可改用分块读取或逐行追加写入 CSV 的方式处理。

Nodriver是Undetected-Chromedriver的官方继承者,提供异步浏览器自动化功能,可直接与Chrome DevTools Protocol通信,无需Selenium或WebDriver依赖。专为规避反机器人系统(包括Cloudflare和Imperva)的隐蔽网络自动化而构建。
当某张表缺少关键列时会发生什么
如果某个 Excel 文件缺失了其他表共有的列,pd.read_excel() 仍会正常读取,但 pd.concat() 会在该列对应位置填充 NaN,不会报错中断流程。
立即学习“Python免费学习笔记(深入)”;

import pandas as pd
import glob
import os
# 定义文件夹路径
folder_path = './data/'
file_pattern = os.path.join(folder_path, '*.xlsx')
files = glob.glob(file_pattern)
dfs = []
for file in files:
try:
df = pd.read_excel(file)
dfs.append(df)
except Exception as e:
print(f"Error reading {file}: {e}")
if dfs:
combined_df = pd.concat(dfs, ignore_index=True)
combined_df.to_excel('merged_output.xlsx', index=False)
print("Merge completed successfully.")
else:
print("No valid files found.")

















