【发布时间】:2018-04-20 15:40:11
【问题描述】:
这就是我想要做的——真的很简单。我有一个包含数据的 pdf 文档,我想使用 python 提取它。这是在我试图从需要定期读取的固定模板中自动提取数据的上下文中。
我正在使用 tabula-py 包,并使用“read_pdf”函数读取数据。问题是它似乎只读取了我需要的部分表格……更具体地说,它只能读取在表格标题中。奇怪的是,如果我使用在线表格工具阅读表格,我不会遇到这个问题。
# Here is the python code to read table content
df = tb.read_pdf(path+name+'.pdf', encoding='latin-1', area=[416.543,25.398,434.903,582.318],spreadsheet=True,pages=2)
# Here is the tabula online tool script:
java -jar tabula-java.jar -a 416.543,25.398,434.903,582.318 -p 2 "$1"
前者产生
«无»类型的对象
而后者产生:
1 2018 Peterbilt Tracteur routier 一些 VIN 号 230 000 $
对表头运行相同的查询会产生所需的结果:
# Here is the python code to read table header
df = tb.read_pdf(path+name+'.pdf',encoding='latin-1',area=[397.418,24.633,417.308,583.083],spreadsheet=True,pages=2)
# Here is the tabula online tool script:
java -jar tabula-java.jar -a 397.418,24.633,417.308,583.083 -p 2 "$1"
前者产量
空 DataFrame 列:[Item, Année, Marque, Carrosserie, No série, Valeur actuelle] 索引:[]
而后者产生
Item Année Marque Carrosserie No série Valeur actuelle
因为 tabula-py 只是 java 包的一个包装器,我原以为两者的行为方式完全相同。我错过了什么?
Windows 10 64 位
tabula-py v1.0.0
Java v8
【问题讨论】: