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
相关推荐
hef2881 小时前
如何生成特定SQL的AWR报告_@awrsqrpt.sql深度剖析单条语句性能Jinkxs1 小时前
从语法纠错到项目重构:Python+Copilot 的全流程开发效率提升指南技术专家1 小时前
Stable Diffusion系列的详细讨论 / Detailed Discussion of the Stable Diffusion Series段一凡-华北理工大学2 小时前
【大模型+知识图谱+工业智能体技术架构】~系列文章01:快速了解与初学入门!!!IT小Qi2 小时前
iperf3网络测试工具以神为界2 小时前
Python入门实操:基础语法+爬虫入门+模块使用全指南xcjbqd02 小时前
Python API怎么加Token认证_JWT生成与验证拦截器实现io_T_T2 小时前
如何调用google api 进行开发(使用免费版本)广师大-Wzx3 小时前
一篇文章看懂MySQL数据库(下)hef2884 小时前
golang如何使用range over func_golang range over func迭代器使用方法