首页 > 解决方案 > Python-Camelot 提取空表

问题描述

我正在使用 Camelot 通过以下命令提取 PDF 的多个部分。

cgl_section = camelot.read_pdf(filename, flavor='stream', 
              table_areas=['35,490,155,483', '53,480,110,470', '117,480,155,470', 
                           '38,469,106,456', '39,454,105,445', '38,430,155,420', 
                           '38,418,77, 410'])

当 PDF 实际包含这些区域中的数据时,这运行良好。但我不希望在每个解析的 PDF 中都有数据,有些返回的是空的。当返回的数据不是表格并且只有一列时,我收到以下错误。

UserWarning: No tables found in table area 1

ValueError: min() arg is an empty sequence

我需要一种方法来提取所有 PDF 中的这些特定区域,但之后忽略空的区域。需要能够有序地使用提取的数据。

也欢迎任何其他建议

TIA

标签: pythonpandasdataframepdf-extractionpython-camelot

解决方案


也许选项 table_regions(在 0.7 中引入)可以帮助你。

https://camelot-py.readthedocs.io/en/master/user/advanced.html#specify-table-regions

When table_regions is specified, Camelot will only analyze the specified regions to look for tables.

推荐阅读