How to Get Extracted Data into pandas

Skip writing a custom PDF or OCR parser. Extract the document with Datafromfile, then load the result straight into a pandas DataFrame.

Need to import data into pandas from a PDF, scanned document, or photo? pandas can't read a PDF, a scanned document, or a photo directly, there's no pd.read_pdf(). Datafromfile handles that conversion; pandas takes it from there.

The actual steps

  1. Extract your document with Datafromfile and export it as CSV, XLSX, or JSON.
  2. Load it with pandas:
import pandas as pd

# From CSV
df = pd.read_csv("extracted-data.csv")

# From Excel
df = pd.read_excel("extracted-data.xlsx")

# From JSON
df = pd.read_json("extracted-data.json")
```

  1. From there, it's a normal DataFrame, use it however you already work with tabular data in pandas.

A couple of real gotchas worth knowing

  • Numbers extracted as text. If a column has mixed formatting (say, some values with a currency symbol slipped through), pandas will read the whole column as strings (object dtype) instead of numbers. Check with df.dtypes and clean with pd.to_numeric(df['column'], errors='coerce') if needed.
  • Dates as strings by default. Use pd.read_csv(..., parse_dates=['date_column']) or pd.to_datetime() afterward to get real datetime objects instead of plain text.

Combining multiple extractions into one DataFrame

Batch-processing several documents (a folder of invoices, say) through Datafromfile produces one export per document. pd.concat() combines them into a single DataFrame for analysis:

import glob

files = glob.glob("extracted-*.csv")
df = pd.concat([pd.read_csv(f) for f in files], ignore_index=True)
```

ignore_index=True matters here, without it the combined DataFrame keeps each file's original row numbers, which means duplicate index values across files rather than one continuous range.

Handling a multi-sheet Excel export

A document with more than one table (a summary page and a detail page, for example) can export as a multi-sheet XLSX rather than a single flat table. pd.read_excel() only loads the first sheet by default, pass sheet_name=None to get a dictionary of DataFrames keyed by sheet name instead, or sheet_name='Sheet2' for one specific sheet.

FAQ

Can pandas read a PDF directly? No, pandas has no PDF reader built in. You need an extraction step first, whether that's Datafromfile or a table-extraction library like Camelot or Tabula for native (non-scanned) PDFs specifically.

Does the CSV or XLSX export from Datafromfile need any cleanup before pandas can read it? Usually not for a basic load, but check df.dtypes after loading, since numbers or dates that came through with inconsistent formatting on the source document can load as text.

What's the fastest way to check if a column loaded correctly? df.dtypes shows every column's inferred type at a glance, object where you expected int64 or float64 is the usual sign a numeric column loaded as text.

Feeding the result straight into a pipeline

If the DataFrame is a step in a larger script rather than something you're inspecting by hand, Datafromfile's API can be called directly instead of downloading a file and reading it from disk, skipping the export/re-upload round trip entirely for a scheduled or automated job. The returned JSON payload maps onto pd.json_normalize() the same way a manually exported JSON file does, so the loading code stays identical whether the data came from a file or an API response.

A note on encoding and large files

A CSV extracted from a document with non-English characters (accented names, non-Latin currency symbols) can occasionally load with garbled text if pandas guesses the wrong encoding. Passing encoding='utf-8' explicitly to pd.read_csv() covers the vast majority of real cases, since that's the encoding Datafromfile's own export uses. For a very large batch export, chunksize on pd.read_csv() reads the file in pieces rather than loading the whole thing into memory at once, worth knowing about even if most single-document extractions are small enough not to need it.

Try it

Extract your document with Datafromfile, export to CSV or XLSX, and load it with pd.read_csv() or pd.read_excel().

Keep reading