我正在尝试从pdf中提取表格。Tabula帮助我从pdf中提取表格。
目前我面临的问题是,如果任何表格跨越多个页面,Tabula会将每个新的页面表格内容视为新的表格。
有没有办法或逻辑来克服这个问题?
代码:
from tabula import read_pdf
df = read_pdf("SampleTableFormat2pages.pdf", multiple_tables=True, pages="all")
print len(df)
print df输出
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来理解表格边界和下一页跨度?
或任何其他库,可以帮助这一点?
发布于 2018-09-26 09:52:44
我会建议一次转到每一页,并连接最后的表格。您可以使用此函数计算pdf中的页数
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()))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 needhttps://stackoverflow.com/questions/52234696
复制相似问题