簡體   English   中英

tabula-py無法讀取pdf文件

[英]tabula-py unable to read pdf file

我的代碼:

import tabula
import os

dir_path = os.path.dirname(os.path.realpath(__file__))
file_path = dir_path + '\ALPINE_' + str(20191107) + '.pdf'
print(file_path)
df = tabula.read_pdf('ALPINE_20191107.pdf',multiple_tables=True, pages="all")

結果:

runfile('C:/Users/Admin/Documents/lucas/testTabula.py.py', wdir='C:/Users/Admin/Documents/lucas')
Traceback (most recent call last):

  File "<ipython-input-29-a6b390aef3cf>", line 1, in <module>
    runfile('C:/Users/Admin/Documents/lucas/sem título0.py', wdir='C:/Users/Admin/Documents/lucas')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Admin/Documents/lucas/sem título0.py", line 12, in <module>
    df = tabula.read_pdf('ALPINE_20191107.pdf',multiple_tables=True, pages="all")

  File "C:\ProgramData\Anaconda3\lib\site-packages\tabula\io.py", line 332, in read_pdf
    return _extract_from(raw_json, pandas_options)

  File "C:\ProgramData\Anaconda3\lib\site-packages\tabula\io.py", line 664, in _extract_from
    df[c] = pd.to_numeric(df[c], errors="ignore")

  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\tools\numeric.py", line 138, in to_numeric
    raise TypeError("arg must be a list, tuple, 1-d array, or Series")

TypeError: arg must be a list, tuple, 1-d array, or Series

它的功能似乎不起作用。 我可以直接輸入路徑以使其更簡單,但它也不起作用。 pdf 文件可能有問題,但我已經看到它在具有相同腳本和相同文件的另一個環境中工作。

我已經按照文檔在兩個可能的路徑('C:\\ 我也嘗試添加 jdk 但也沒有解決。

我注意到提到熊貓的錯誤​​,所以它可能與我的版本(最新版本)有沖突,但我不確定。

python 是 3.7.4,java 是迄今為止最新的

我有同樣的問題。 我使用的是使用 pip 安裝的版本,即 tabula-py 2.0.0。 我卸載了該版本,並使用 conda install -c conda-forge tabula-py 從 Anaconda 安裝,當前版本是 tabula-py 1.4.1,解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM