Reputation: 105
I am trying to extract only tables from pdf using tabula package and writing the output into csv, Unfortunately, the below code gives me an error as "NameError: name 'tabula' is not defined"
How to fix this issue
Code:
!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')
Error:
"NameError: name 'tabula' is not defined"
Upvotes: 2
Views: 2684
Reputation: 62
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
You using the method but not imported so, it's giving this error
Upvotes: -1
Reputation: 161
Heres an explanation. Every time you use from module import function
it will take the function, not the entire library and the functions, so if you want to use that tabula.to_csv()
function, you will need to import the whole library, using import tabula
.
Other Method:
You can use to_csv()
and import it with from tabula import to_csv
Upvotes: 0