首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提取跨越多个页面的表

提取跨越多个页面的表
EN

Stack Overflow用户
提问于 2018-09-08 19:06:09
回答 1查看 8.7K关注 0票数 4

我正在尝试从pdf中提取表格。Tabula帮助我从pdf中提取表格。

目前我面临的问题是,如果任何表格跨越多个页面,Tabula会将每个新的页面表格内容视为新的表格。

有没有办法或逻辑来克服这个问题?

代码:

代码语言:javascript
复制
from tabula import read_pdf
df = read_pdf("SampleTableFormat2pages.pdf", multiple_tables=True, pages="all")
print len(df)
print df

输出

代码语言:javascript
复制
2
[        0       1       2       3       4
0  Label1  Label2  Label3  Label4  Label5
1   Row11   Row12   Row13   Row14   Row15
2   Row21   Row22   Row23   Row24   Row25
3   Row31   Row32   Row33   Row34   Row35,        0      1      2      3      4
0  Row41  Row42  Row43  Row44  Row45
1  Row51  Row52  Row53  Row54  Row55]

有没有逻辑来解释Tabula来理解表格边界和下一页跨度?

或任何其他库,可以帮助这一点?

EN

回答 1

Stack Overflow用户

发布于 2018-09-26 09:52:44

我会建议一次转到每一页,并连接最后的表格。您可以使用此函数计算pdf中的页数

代码语言:javascript
复制
import re
def count_pdf_pages(file_path):
   rxcountpages = re.compile(r"/Type\s*/Page([^s]|$)", re.MULTILINE|re.DOTALL)
   with open(file_path, "rb") as temp_file:
   return len(rxcountpages.findall(temp_file.read()))

代码语言:javascript
复制
df=pd.DataFrame([])
df_combine=pd.DataFrame([])
for pageiter in range(pages):
            df = tabula.read_pdf("SampleTableFormat2pages.pdf",pages=pageiter+1, guess=False)
            #If you want to change the table by editing the columns you can do that here.
            df_combine=pd.concat([df,df_combine],) #again you can choose between merge or concat as per your need
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52234696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档