【问题标题】:Why do I get an empty dataframe when using Tabula?为什么我在使用 Tabula 时会得到一个空的数据框?
【发布时间】:2020-12-01 17:24:25
【问题描述】:
我有以下代码:
df = tabula.read_pdf(r'C:\Users\Max12\Desktop\xml\pdfminer\attachments\Factuur 78692661.PDF', area=[375,7,76,558], pages = 1)
df1 = pd.DataFrame.from_records(df)
print(df1)
应该根据附件找到。我怎么找不到这张桌子?
请参阅附件以供参考。
Measurements
Jupyter notebook
【问题讨论】:
标签:
python
dataframe
tabula
【解决方案1】:
问题出在代码中提到的area参数上。
根据Tabula Documentation,面积参数必须提到如下:
area (list of float, list of list of float, optional) –
Portion of the page to analyze(top,left,bottom,right). Default is entire page.
假设你需要从页面中间提取数据,那么参考上面的参数:
top == distance between **starting** of your desired data from the top of the page
left == distance between **starting** of your desired data from the left of the page
bottom == distance between **ending** of your desired data from the top of the page
right == distance between **ending** of your desired data from the left of the page
因此,区域参数列表中的第一个值必须小于第三个值。
同样,区域参数列表中的第二个值必须小于第四个值。
只有这样,tabula 才能通过给定的坐标创建表格。