【问题标题】:How to provide table areas as an input in camelot-Python如何在 camelot-Python 中提供表格区域作为输入
【发布时间】:2021-10-01 15:45:53
【问题描述】:

我正在制作一个 python 脚本,用户可以在其中提供 pdf 和表格区域,然后提取表格并将其转换为 csv 文件。但是如何在此处获取输入并将其添加到命令中。

import camelot
import pandas as pd
pdf_line = input("Enter pdf path: ")
#print(pdf_line)
#tables = camelot.read_pdf("/Users/kvidushi/Desktop/1.pdf")
tables = camelot.read_pdf(pdf_line)
x1 =float(input("Enter coordinate x1: "))
y1 =input("Enter coordinate y1: ")
x2 = input("Enter coordinate x2: ")
y2 = input("Enter coordinate y2: ")
print(type(x1))
#regions="['"+x1+"','"+y1+"','"+x2+"','"+y2+"']"
#regions = ['50', '499','566','420']
#tables=camelot.read_pdf(pdf_line, table_regions=regions)
tables = camelot.read_pdf(pdf_line, flavor='stream', table_areas=['x1,x2,x3,x4'],Index='false',ignore_index=True)
#tables = camelot.read_pdf(pdf_line, flavor='stream', table_areas=['50,499,566,420'],Index='false',ignore_index=True)
#tables[0].df.columns = tables[0].df.iloc[0]
#tables[0].df =tables[0].df.drop(0)
#tables.export('tables.xls', f='excel')
print(tables[0].df)
tables[0].to_excel("1.xlsx", index=False)

【问题讨论】:

  • 问题的所有这些评论行的目的是什么(它是噪音)

标签: python pandas data-extraction python-camelot


【解决方案1】:

你试过了吗:

table_areas=[f'{x1},{y1},{x2},{y2}']

【讨论】:

  • table_areas=[f'{x1},{y1},{x2},{y2}'] 似乎更正确。
  • @StefanoFiorucci-anakin87 谢谢,我只看了read_pdf() 调用的行,为什么OP 使用x3x4,因为它们永远不会被分配/使用程序
猜你喜欢
  • 2019-05-28
  • 1970-01-01
  • 2019-04-12
  • 1970-01-01
  • 2020-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-22
相关资源
最近更新 更多