我使用Python3中的tabla包从PDF中的表中获取数据
我正在尝试在线从多个PDF导入表(例如http://trreb.ca/files/market-stats/community-reports/2019/Q4/Durham/AjaxQ42019.pdf),但我甚至无法正确导入一个表
以下是我运行的代码:
! pip install -q tabula-py
! pip install pandas
import pandas as pd
import tabula
from tabula import read_pdf
pdf = "http://trebhome.com/files/market-stats/community-reports/2019/Q4/Durham/AjaxQ42019.pdf"
data = read_pdf(pdf, output_format='dataframe', pages="all")
data
这将提供以下输出:
[ Community Sales Dollar Volume ... Active Listings Avg. SP/LP Avg. DOM
0 Ajax 391 $265,999,351 ... 73 100% 21
1 Central East 32 $21,177,488 ... 3 99% 26
2 Northeast Ajax 70 $50,713,199 ... 18 100% 21
3 South East 105 $68,203,487 ... 15 100% 20
[4 rows x 9 columns]]
除了在“中东”之后每隔一行就漏掉一行之外,这似乎是可行的。以下是问题中的实际表格,来自上面代码中url处的pdf: Ajax Q4 2019
我还尝试过摆弄read_pdf
函数中的一些选项,但效果甚微
最终目标将是一个脚本,它循环遍历所有这些“社区报告”(有很多),从PDF中提取所有这些表,并将它们整合到python中的一个数据帧中进行分析
如果问题不清楚,或者需要更多信息,请让我知道!我对python和堆栈交换都是新手,所以如果我没有正确地构建东西,我深表歉意
当然,任何帮助都将受到极大的感谢
布莱恩
以下代码几乎起作用:
并给出输出:
这里唯一的问题是,
convert_into
命令没有找到最后一列“Avg.DOM”根据我的分析,这并不重要,但对于其他试图以类似方式拉表的人来说,这肯定是一个问题
相关问题 更多 >
编程相关推荐