import pdfplumber
import pandas as pd
def extract_tables_to_excel(pdf_path, excel_path):
# 打开PDF文件
with pdfplumber.open(pdf_path) as pdf:
# 创建一个空的DataFrame列表,用于存储所有表格数据
all_tables = []
# 遍历PDF的每一页
for page in pdf.pages:
# 提取当前页的表格
tables = page.extract_tables()
# 将每页的表格转换为DataFrame,并添加到all_tables列表中
for table in tables:
df = pd.DataFrame(table)
all_tables.append(df)
# 将所有表格数据合并为一个DataFrame
combined_tables = pd.concat(all_tables, ignore_index=True)
# 将合并后的表格数据保存到Excel文件中
combined_tables.to_excel(excel_path, index=False)
# PDF文件路径
pdf_path = '1.pdf'
# Excel文件路径
excel_path = 'output_tables.xlsx'
# 调用函数
extract_tables_to_excel(pdf_path, excel_path)
Python应用—从pdf文件中提取表格,并且保存在excel中
翻车吧奥斯卡2024-07-21 21:45
相关推荐
默_笙1 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的qq_426003961 天前
启动playwright录制codegen生成自动化测试脚本虎头金猫1 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺长沙三为智能科技1 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单伞伞悦读1 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__只睡四小时1 天前
Canvas 弹道联机实战:700 行 + 固定时间步长奇思妙想聪明勤奋的小羊1 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派lpfasd1231 天前
2026年第38周GitHub趋势周报IZero071 天前
Jev 与 Laya