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
相关推荐
2301_809204703 小时前
JavaScript中严格模式use-strict对引擎解析的辅助.txtzjy277774 小时前
mysql如何选择合适的索引类型_mysql索引设计实战Aaswk4 小时前
Java Lambda 表达式与流处理:mnong4 小时前
附图报价系统设计分析5万邦科技Lafite4 小时前
京东item_get接口实战案例:实时商品价格监控全流程解析Cyber4K5 小时前
【Python专项】进阶语法-系统资源监控与数据采集(1)苍煜6 小时前
Java开发IO零基础吃透:BIO、NIO、同步异步、阻塞非阻塞AllData公司负责人7 小时前
通过Postgresql同步到Doris,全视角演示AllData数据中台核心功能效果,涵盖:数据入湖仓,数据同步,数据处理,数据服务,BI可视化驾驶舱Flittly8 小时前
【LangGraph新手村系列】(5)时间旅行:浏览历史、分叉时间线与修改过去2301_782040458 小时前
CSS Flex布局中如何实现导航栏与Logo的左右分布_利用justify-content- space-between