Table extract PDF2CSV

From Essential
Revision as of 21:34, 12 March 2024 by Tcepo (talk | contribs) (Created page with "Astuce pour convertir correctement des tableaux PDF à CSV <pre> import camelot # Use the 'file_path' variable to specify the path to your PDF file_path = '/home/noname/Downl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Astuce pour convertir correctement des tableaux PDF à CSV

import camelot

# Use the 'file_path' variable to specify the path to your PDF
file_path = '/home/noname/Downloads/liste_nationale_internet_310719.pdf'

# Extract tables from the PDF
tables = camelot.read_pdf(file_path, pages='all', flavor='stream')

for i, table in enumerate(tables):
    # Convert table to DataFrame
    df = table.df

    # Define CSV file path, unique for each table
    csv_file_path = f'table_{i}.csv'

    # Export the DataFrame to a CSV file
    df.to_csv(csv_file_path, index=False)