【问题标题】:Using the PDF file names and coordinates for camelot and getting the table details使用 camelot 的 PDF 文件名和坐标并获取表格详细信息
【发布时间】:2021-03-10 00:06:11
【问题描述】:

我在 excel 的一列中有 pdf 图像以及它的 camelot 坐标,它们中的每一个都在各自的行中,下面是一个简短的外观:-

文件名 X1_Camelot Y1_Camelot x2_Camelot Y2_Camelot 路径/到/pdf_file/folder/1.pdf 16 77 80 540 路径/到/pdf_file/folder/2.pdf 20 300 40 260 路径/到/pdf_file/folder/3.pdf 40 90 200 340 路径/到/pdf_file/folder/4.pdf 20 50 100 440

我想编写一个 python 脚本,它会在每个 pdf 文件中获取其每个 camelot 版本的坐标,然后将值放入下面的函数中:-

tables = camelot.read_pdf('table_regions.pdf', table_regions=['170,370,560,270']) 表格[0].df

我想要输入 csv 文件中包含这些列的每个 PDF 的结果。

我尝试使用 for 循环和 df.iterrows() 但没有成功。

【问题讨论】:

  • 您能展示一下您尝试过的 for 循环吗?我看不出有什么理由不能使用它,如果你告诉我你尝试了什么,我可以解决它:)
  • import camelot import pandas as pd df = pd.read_csv("file.csv") for ind, row in df.iterrows(): image_name = row['full_path'] x1_cam = row[' X1_Camelot'] x2_cam = row['X2_Camelot'] y1_cam = row['Y1_camelot'] y2_cam = row['Y2_camelot'] 表格 = camelot.read_pdf('table_regions.pdf', table_regions=[x1_cam, y1_cam, x2_cam, y2_cam] ) table_details = 表[0].df1 print(table_details)

标签: python pdf python-camelot


【解决方案1】:
with open('data.csv', 'r') as file:
    data = file.read().split('\n')[1:]
    for line in data:
        fields = line.split(',')
        path = fields[0]
        x1,y1,x2,y2 = int(fields[1]),int(fields[2]),int(fields[3]),int(fields[4])

【讨论】:

    猜你喜欢
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多