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

问题描述

我正在制作一个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,table_areas=['50,499,566,420'],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}']

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...