camelot pdf提取表格实践(记录)

参考:
巧用Python的camelot库批量提取PDF发票信息
关于文本pdf的表格抽取

AttributeError: module ‘camelot‘ has no attribute ‘read_pdf‘及类似问题解决办法
camelot 参数
https://blog.csdn.net/INTSIG/article/details/123000010

在这里插入图片描述
报错解决:
ModuleNotFoundError: No module named ‘Workbook’ xlwt,是版本太低,升级版本即可。 pip install --upgrade xlwt

介绍:
camelot方法有两种解析模式:流解析(stream)、格子解析(lattice),其中格子解析能够保留表格完整的样式,对于复杂表格来说要优于流解析模式。同时,camelot方法默认格子解析(lattice),而采用这种解析方式,需要安装ghostscript。

camelot是一个可以从可编辑的pdf文档中抽取表格的开源框架,与pdfplumber相比,其功能完备性差了点,除了表格抽取之外,并不能用它从pdf文档中解析出字符、单词、文本、线等较为低层次的对象。

下载ghostscript https://www.ghostscript.com/releases/gsdnld.html

参数

在这里插入图片描述
在这里插入图片描述

代码

import camelot
import pandas as pd
# 使用Camelot读取PDF文件中的表格
tables = camelot.read_pdf('pdf.pdf', pages='all', flavor='lattice')

# 将所有表格转换为 DataFrame 并合并
all_data = pd.concat([table.df for table in tables], ignore_index=True)

all_data.to_excel('all_data.xlsx',index=False)

识别效果:不太理想,文本排序有问题。pdfplumber提取表格效果会更好,但是也有少部分数据可能错行
在这里插入图片描述

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值