我试图使用tabula包从pdf中只提取表,并将输出写入csv,不幸的是,下面的代码给出了一个错误,即"NameError: name‘tabula“未定义
如何解决这个问题
码
!pip install tabula-py
from tabula import read_pdf
from tabula.io import read_pdf
file = r"url"
df = read_pdf(file, pages='all')
tabula.to_csv('output.csv', encoding='utf-8')错误:
"NameError: name 'tabula' is not defined"发布于 2021-03-15 09:09:18
这是一个解释。每次使用from module import function时,它都会使用函数,而不是整个库和函数,因此,如果要使用该tabula.to_csv()函数,则需要使用import tabula导入整个库。
其他方法:
您可以使用to_csv()并使用from tabula import to_csv导入它。
发布于 2021-03-15 09:16:12
from tabula import read_pdf
from tabula.io import read_pdf
file = r"url"
df = read_pdf(file, pages='all')
tabula.to_csv('output.csv', encoding='utf-8') # from tabula import to_csv您使用该方法,但没有导入--因此,它会出现以下错误
https://stackoverflow.com/questions/66635076
复制相似问题