【问题标题】:Camelot-py not detecting two lines of text in one rowCamelot-py 没有在一行中检测到两行文本
【发布时间】:2020-06-23 22:54:33
【问题描述】:

使用 Camelot-py 从 .PDF 中抓取表格数据,它不会拾取堆叠的文本行(请参阅下面的第 9 行和第 10 行)

Rows 9 and 10 are void of text for account.

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

这是我拥有的 .ipynb 格式的代码。第一个块用于按预期拉取的第一个表,第二个用于第 9 页。

表格

tables= camelot.read_pdf(r'C:\PDFFilePath', pages='9', line_scale=40)
    tables[0].to_csv(r'Loans&Leases')
    camelot.plot(tables[0], kind ='contour')
    plt.show()

使用 MatPlotLib,我可以看到 Camelot 正确检测了第 9 页的表格区域/网格。

plot table area

plot grid

这是 PDF 的 Google Drive 链接

Call Report PDF

任何见解将不胜感激。

【问题讨论】:

  • 如果可以的话,请分享原始PDF和您尝试过的代码。
  • @anakin87 完成,非常感谢您的关注和关注

标签: python pdf pdf-scraping python-camelot


【解决方案1】:

你的代码是正确的。

如果你尝试输入tables[0].df,这是正确的输出:

所以,在导出为 CSV 时,您的问题是第 10 行和第 11 行中的换行符 (\n)。

解决方案可以是以下代码:

tables= camelot.read_pdf(r'C:\PDFFilePath', pages='9', line_scale=40, strip_text='\n')

使用strip_text,您可以去除不需要的字符(请参阅official documentation)。

现在,如果您将表格导出为 CSV,您将获得:

【讨论】:

    猜你喜欢
    • 2021-12-23
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多