我使用tabula_py读取pdf表。 有些很大。在很多情况下,一个表都在一页以上。 Isuue是tabula_py,它被视为每一页的新表,而不是被视为一个大表。 卡米洛特同样的问题
iCMS 回答:如何使用tabula_py或camelot读取分布在多个页面上的表
您是对的。 Camelot和Tabula都一页一页地工作。
无论如何,您可以编写自定义函数来了解表是否已合并。如果是这样,您可以合并它们的内容并将它们一起对待。
例如,我创建了此函数来处理Camelot输出:
from numpy import allclose
def are_tables_united(table1_dict,table2_dict):
if table2['page']==(table1['page']+1):
if len(table2['cols'])==len(table1['cols']):
# extract the vertical coordinates of the tables
_,y_bottom_table1,_,_=table1['_bbox']
_,y_top_table2=table2['_bbox']
page_height=792
# If the first table ends in the last 15% of the page
# and the second table starts in the first 15% of the page
if y_bottom_table1<.15*page_height and\
y_top_table2>.85*page_height:
table1_cols=table1['cols']
table2_cols=table2['cols']
table1_cols_width=[col[1]-col[0] for col in table1_cols]
table2_cols_width=[col[1]-col[0] for col in table2_cols]
# evaluate if the column widths of the two tables are similar
return(allclose(table1_cols_width,table2_cols_width,atol=3,rtol=0))
else:
return False
else:
return False
函数参数table1_dict
和table2_dict
是Camelot输出表__dict__
的属性。
例如:
tables=camelot.read_pdf(...)
table1_dict=tables[0].__dict__
table2_dict=tables[1].__dict__