Opening a pdf and reading in tables with python pandas

74,521

Solution 1

you can use tabula https://blog.chezo.uno/tabula-py-extract-table-from-pdf-into-python-dataframe-6c7acfa5f302

from tabula import read_pdf
df = read_pdf('data.pdf')

I can see more in the link!

Solution 2

There is a new version of tabula called tabula-py

pip install tabula-py

the .read_pdf method works just like in the old version, documentation is here: https://pypi.org/project/tabula-py/

Solution 3

In case it is a one-off, you can copy the data from your PDF table into a text file, format it (using search-and-replace, Notepad++ macros, a script), save it as a CSV file and load it into Pandas.

If you need to do this in a scalable way, you might try this product: http://tabula.technology/. I have not used it yet, so I don't know how well it works, but you can explore it if you need it.

Solution 4

I have been doing some tests with Camelot (https://camelot-py.readthedocs.io/en/master/), and it works very good in many situations. And you can try to adjust some parameters if the default ones doesn't work.

It's similar to Tabula, but it use different algorithms (Tabula use the vector data in the PDF and raster the lines of the table; Camelot uses Hough Transform), so you can try both to find the best one.

Both have a web version, so you can try with some example to decide which is the best one for your application.

Solution 5

this is not possible. PDF is a data format for printing. The table structure is therefor lost. with some luck you can extract the text with pypdf and guess the former table columns.

Share:
74,521
ccsv
Author by

ccsv

Using Python for about 6 years mainly for text processing, finance, and scientific computing. Also use Javascript for D3 graphing

Updated on September 30, 2021

Comments

  • ccsv
    ccsv over 2 years

    Is it possible to open PDFs and read it in using python pandas or do I have to use the pandas clipboard for this function?