What is Camelot?

Camelot is a Python library that allows for the easy extraction of data tables from PDFPortable Document Format files. However, this library only works with text-based PDFswhich allow data to be selected through cursor and not with scanned PDFs.

Camelot has multiple settings that can be tweaked for better extraction of data in tables. This offers more control over the extraction process than other available libraries.

Camelot converts data tables in PDFs to dataframes.

Installation

The following command installs Camelot:

pip install "camelot-py[cv]"

Usage

Below is a basic code that reads a table in a PDF and converts it to a CSV and Dataframe:

import camelot
table = camelot.read_pdf('sample.pdf')
print(table)  // Displays the number of tables read from the pdf

table.export('sample_table.csv', f='csv', compress=True) // saves the table to a csv file.

table[0] // displays the table shape

tables[0].df // converts the table to a dataframe.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources