我正在尝试使用 tabula-py 从 PDf 中提取数据并将其保存到 csv。 PDF 包含工单。 PDF 中的数据未格式化为可用表格 - 我需要使用流模式。
通过 Tabula 网络界面,我创建了一个模板,可以使用它来将数据提取到 csv。 我的模板包括 8 个部分。 从 Tabula 导出的 csv 看起来像这样:(虽然没有标题行......)
工号 |
---|
全名 |
电话1 |
电话2 |
地址1 |
地址2 |
电子邮件 |
工作类型1 |
工作类型2 |
使用 tabula-py,我运行代码
df = tabula.read_pdf_with_template("file.pdf","template.tabula-template.json")
print(df)
的输出是:
[Empty DataFrame
Columns: [full name]
Index: [], Empty DataFrame
Columns: [phone1]
Index: [], Empty DataFrame
Columns: [phone2]
Index: [], Empty DataFrame
Columns: [email]
Index: [], address1
0 address2
Columns: [jobtype]
Index: [], Empty DataFrame
Columns: [jobtype2]
Index: [], Empty DataFrame
Columns: [jobnumber]
Index: []]
注意:我把输出文本改成了字段名
我选择的部分都没有标题。请注意,地址部分将地址第 1 行显示为标题,将地址第 2 行显示为值。这是因为地址位于 PDF 中的 2 行。
我有3个问题:
用于产生上述结果的所有代码:
import tabula
import pandas as pd
df = tabula.read_pdf_with_template("file.pdf","template.tabula-template.json")
print(df)