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
相关推荐
Katecat9966319 小时前
【实战分享】基于YOLO11-C3k2-SFHF的车道线与车辆检测实现——道路场景智能识别系统yunhuibin19 小时前
LeNet、AlexNet、VGGNet、NiN总结AALoveTouch19 小时前
逆向利器:Frida HookEmotional。19 小时前
AI Agent 开发实战:用 LangChain 构建智能邮件助手追风少年ii19 小时前
第12篇HD文章--射血分数保留的心力衰竭患者左心室心肌免疫细胞丰度正常Lupino19 小时前
贪小便宜买的 10 元“三无”传感器,看我用 OpenClaw 强行逆袭!Java.慈祥20 小时前
My First AI智能体!!!qq_242188633220 小时前
【零基础使用Trae CN编写第一个AI游戏教程】小雨中_20 小时前
4.1 LLaMA 系列:从 LLaMA-1 到 LLaMA-3小鸡吃米…20 小时前
TensorFlow 模型导出