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 天前
2025年大模型终极横评:GPT-5.2、Banana Pro与DeepSeek V3.2实战硬核比拼(附统一接入方案)刘某的Cloud1 天前
列表、元组、字典、集合-组合数据类型ys~~1 天前
git学习Mqh1807621 天前
day46 Grad-CAM郝学胜-神的一滴1 天前
Python魔法函数一览:解锁面向对象编程的奥秘白露与泡影1 天前
使用systemd,把服务装进 Linux 心脏里~yaoh.wang1 天前
力扣(LeetCode) 100: 相同的树 - 解法思路Sunsets_Red1 天前
2025 FZYZ夏令营游记guslegend1 天前
第2章:LangChain大模型工具开发(Agent工具能力)草帽lufei1 天前
Ubuntu中为AI Agent相关开发配置Python环境