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
相关推荐
Keep_Trying_Go11 分钟前
基于无监督backbone无需训练的类别无关目标统计CountingDINO算法详解weixin_4331793341 分钟前
python - for循环,字符串,元组基础^哪来的&永远~1 小时前
Python 轻量级 UI:EEG 与 fNIRS 预处理图形界面AI大佬的小弟1 小时前
Python基础(11):Python中函数参数的进阶模式详解智算菩萨1 小时前
Python可以做哪些小游戏——基于Python 3.13最新特性的游戏开发全指南(15万字超长文章,强烈建议收藏阅读)智航GIS1 小时前
9.1 多线程入门nvd111 小时前
FastMCP 开发指南: 5分钟入门weixin_433179332 小时前
Python - word jumble游戏拾荒的小海螺3 小时前
C#:PdfiumViewer 高效解析和操作 PDF 的技术指南Iridescent11213 小时前
Iridescent:Day48