【问题标题】:Tables not detected with tabula and camelottabula 和 camelot 未检测到表
【发布时间】:2021-11-22 15:08:39
【问题描述】:

我试图从我认为格式不正确的 PDF 中提取表格。这些 PDF 中的表格具有表格格式,但没有用垂直边框正确包围。 我将附上示例 pdf 并与两个库一起输出。当我尝试使用 tabula 进行表格检测时,pdf 中的所有页面上都会返回一个空白数据帧。

为单个页面输入 0,为所有页面输入 1,为特定页面输入 2:2 输入页码:25 在此页面上没有按 tabula 找到的表格。

当我使用 camelot 时,我使用 flovor='lattice' 时同样没有响应

输入0表示单页,1表示所有页面,2表示表格中的页面被tabula检测到,3表示特定页面:3 输入 0 表示晶格或输入 1 表示流:0 输入页码:25 在此页面上找不到 camelot 的表格。

当我使用flovor='stream' 时,我得到一个数据框,其中每一行都使用制表符分隔的数据逐行读取,但它也会在该数据框中包含普通文本。

输入0表示单页,1表示所有页面,2表示表格中的页面被tabula检测到,3表示特定页面:3 输入 0 代表晶格或 1 代表流:1 输入页码:25

我只需要一种有效的方法来检测表格并在不存在垂直封闭表格行的情况下提取相同的数据。如果表格是由垂直和水平线包围的正确格式,那么 tabula 和 camelot 库都可以正常工作。

【问题讨论】:

    标签: python pdf nlp python-camelot tabula-py


    【解决方案1】:

    此方法可能会帮助您: https://camelot-py.readthedocs.io/en/master/user/advanced.html#specify-column-separators

    您可以通过传递 x 坐标找到指定 camelot 的垂直分隔符,首先您应该使用 camelot 中的“.plot()”方法查看 pdf 中的表格并记下您想要垂直的 x 坐标然后将分隔符传入如下:

    # to get the x-coordinates
    tables = camelot.read_pdf('your_pdf.pdf')
    camelot.plot(tables[0], kind='text').show()
    
    #to pass the x-coordinates
    camelot.read_pdf('your_pdf.pdf', flavor='stream', columns=['x1,x2']) 
    

    【讨论】:

      【解决方案2】:

      未检测到带有 tabula 和 camelot 的表格

      我最近一直致力于从 PDF 中提取表格。

      Tabulacamelot 对我也不起作用,但 pdfplumber 得到了我需要的结果。

      import pdfplumber
      pdf = pdfplumber.open(filepath)
      table = pdf.pages[1].extract_table(table_settings=
      {"vertical_strategy": "text", "horizontal_strategy": "text"})
      df = pd.DataFrame(table, columns=table)
      df.to_csv(outfile2, mode='a', index=False)
      

      【讨论】:

        猜你喜欢
        • 2022-01-24
        • 1970-01-01
        • 1970-01-01
        • 2021-12-23
        • 2022-12-03
        • 2020-06-23
        • 2018-12-11
        • 2023-01-17
        • 2019-05-28
        相关资源
        最近更新 更多