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
相关推荐
likerhood37 分钟前
java中`==`和`.equals()`区别qq_283720051 小时前
Python Celery + FastAPI + Vue 全栈异步任务实战2401_885885041 小时前
营销推广短信接口集成:结合营销策略实现的API接口动态变量填充方案telllong2 小时前
Python异步编程从入门到不懵:asyncio实战踩坑7连发lulu12165440784 小时前
Claude Code Harness架构技术深度解析:生产级AI Agent工程化实践7年前端辞职转AI6 小时前
Python 文件操作龙文浩_6 小时前
AI梯度下降与PyTorch张量操作技术指南呱牛do it6 小时前
企业级绩效考核系统设计与实现:基于FastAPI + Vue3的全栈解决方案7年前端辞职转AI6 小时前
Python 容器数据类型云霄IT6 小时前
安卓开发之java转dex再转smali