Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tabla py没有正确拆分列_Python_Python 3.x_Pdf_Tabula - Fatal编程技术网

Python tabla py没有正确拆分列

Python tabla py没有正确拆分列,python,python-3.x,pdf,tabula,Python,Python 3.x,Pdf,Tabula,我刚刚发现了tablapy(当然还有tablajava)从pdf中提取表格的乐趣。我现在正在为我的工作编写一个脚本,从pdf表格中读取一些数据,稍微清理一下,然后将其导出到excel中。我每天使用的pdf格式都是一样的,表格总是在某个区域。为了检测区域,我使用tabla.exe:我选择表格,可视化预览(看起来不错),然后导出脚本,以便查看tabla.exe使用的-a参数。然后,我在Python中的命令中使用了这一点,即: df = tabula.read_pdf(os.fsdecode(dire

我刚刚发现了tablapy(当然还有tablajava)从pdf中提取表格的乐趣。我现在正在为我的工作编写一个脚本,从pdf表格中读取一些数据,稍微清理一下,然后将其导出到excel中。我每天使用的pdf格式都是一样的,表格总是在某个区域。为了检测区域,我使用tabla.exe:我选择表格,可视化预览(看起来不错),然后导出脚本,以便查看tabla.exe使用的-a参数。然后,我在Python中的命令中使用了这一点,即:

df = tabula.read_pdf(os.fsdecode(directory)+filename, encoding = 'ISO-8859-1',
stream=True, area = "81.106,302.475,384.697,552.491", pages = 2, pandas_options={'header':None})
我使用encoding参数是因为标准utf-8返回错误,而stream方法是因为它在tabla.exe中显示了一个很好的提取表。但是,dataframe有一个问题,因为前两列(在tabla.exe的预览中正确显示为两个不同的列)实际上是一列,因此名称和值混合在一起


您知道为什么同一区域在tabla py和tabla.exe中产生两种不同的结果吗?多谢各位

在GitHub上找到了答案:tabla-py的“guess”选项默认设置为True。因此,要更正差异,只需添加guess=False,输出将是相同的

    df = tabula.read_pdf(os.fsdecode(directory)+filename, encoding = 'ISO-8859-1', 
         stream=True, area = "81.106,302.475,384.697,552.491", pages = 2, guess = False,  pandas_options={'header':None})

如果其他人难以确定表和列的位置,您可以使用Adobe Acrobat轻松找到精确的尺寸。在Adobe Acrobat中打开pdf,启用标尺,然后将其设置为点。放大视图,您可以看到要拆分区域/表格的精确点测量值