1

When exporting a PDF file to csv, it returns an error:writeheader() takes 1 positional argumentbut 2 were given

from tabula import read_pdf
from tabulate import tabulate
import csv

df = read_pdf("asd.pdf")
print(df)


with open('ddd.csv', "w", newline="") as file:
    columns = ['specialty ',"name",'number_of_seats','Total_seats,' "document_type", "concent"]
    writer = csv.DictWriter(file, fieldnames=columns)
    writer.writeheader(df)
tody22
  • 11
  • 2

1 Answers1

0

Code copied from http://theautomatic.net/2019/05/24/3-ways-to-scrape-tables-from-pdfs-with-python/, there is also more details ...

import tabula
 
file = "http://lab.fs.uni-lj.si/lasin/wp/IMIT_files/neural/doc/seminar8.pdf"
 
#tables = tabula.read_pdf(file, pages = "all", multiple_tables = True)

# output just the first table in the PDF to a CSV
tabula.convert_into(file, "output.csv", output_format="csv")
 
# output all the tables in the PDF to a CSV
tabula.convert_into(file, "output.csv", output_format="csv", pages='all')
ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • When I run the code it gives an error:build_options() got an unexpected keyword argument 'all' – tody22 Mar 16 '21 at 14:26