如何在 camelot-Python 中提供 table 区域作为输入

How to provide table areas as an input in camelot-Python

我正在制作一个 python 脚本,用户可以在其中提供 pdf 和 table 区域,然后提取 table 并将其转换为 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)

你试过了吗:

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