使用 tabula 从网页中的 pdf 中提取表格时出现问题(Python 中的网页抓取)
当我从页面中提取表格时,我设法毫无问题地提取,但数据是乱序的。例如,一列中的数据显示为另一列的标题,我该如何解决此问题?我的代码:
from tabula import read_pdf
url='https://becas.osinergmin.gob.pe/seccion/centro_documental/hidrocarburos/SCOP/SCOP-DOCS/2022/01-Demanda-Nacional-Combustibles-Liquidos-Enero-2022.pdf'
df=read_pdf(url, pages=1)
df
提前致谢。
when I extract a table from a page, I manage to extract without problems, but the data is out of order. There is data from one column that appears as the title of another column for example, how can I fix this? My code:
from tabula import read_pdf
url='https://becas.osinergmin.gob.pe/seccion/centro_documental/hidrocarburos/SCOP/SCOP-DOCS/2022/01-Demanda-Nacional-Combustibles-Liquidos-Enero-2022.pdf'
df=read_pdf(url, pages=1)
df
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案:使用 tabula 程序查找坐标。我们只需要上传程序: https://tabula.technology/ 并下载 JSON 文件即可查看坐标。我们需要按以下顺序将其放入 read_pdf 函数的“区域”参数中:顶部(y1)、左侧(x1)、底部(y2)和右侧(x2)距离。
现在我已经为具有相同坐标的所有 pdf 创建了一个循环,并且运行良好。
I found the solution: Use tabula program to find coordinates. We just need upload the program: https://tabula.technology/ and dowload the JSON file to see the coordinates. We need to put it in "area" argument of read_pdf function in this order: top(y1), left (x1) , bottom (y2) and right (x2) distance.
Now I've created a loop for all pdfs with the same coordinates and It's working well.