使用 tabula 从网页中的 pdf 中提取表格时出现问题(Python 中的网页抓取)

发布于 2025-01-16 19:04:00 字数 325 浏览 3 评论 0原文

当我从页面中提取表格时,我设法毫无问题地提取,但数据是乱序的。例如,一列中的数据显示为另一列的标题,我该如何解决此问题?我的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不如归去 2025-01-23 19:04:00

我找到了解决方案:使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文