This documentation page is also available as an interactive notebook. You can launch the notebook in
Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
above links.
Load data from CSV and Excel files into Pixeltable tables for processing
and analysis.
Problem
You have data in CSV or Excel files that you want to process with AI
models, add computed columns to, or combine with other data sources.
Solution
What’s in this recipe:
- Import CSV files directly into tables
- Import from Pandas DataFrames
- Handle different data types
You use pxt.create_table() with a source parameter to create a table
from a CSV file, or insert DataFrame rows into an existing table.
Setup
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘import_demo’.
<pixeltable.catalog.dir.Dir at 0x141eca110>
Import CSV directly
Use create_table with source to create a table from a CSV file:
Created table ‘population’.Inserting rows into `population`: 0 rows [00:00, ? rows/s]
Inserting rows into `population`: 234 rows [00:00, 9032.63 rows/s]
Inserted 234 rows with 0 errors.
Import from Pandas DataFrame
You can also create a DataFrame first and insert it:
Created table ‘users’.Inserting rows into `users`: 0 rows [00:00, ? rows/s]
Inserting rows into `users`: 3 rows [00:00, 923.31 rows/s]
Inserted 3 rows with 0 errors.
3 rows inserted, 6 values computed.
Explanation
Source types supported:
Type inference:
Pixeltable automatically infers column types from CSV data. You can
override types using schema_overrides.
Large files:
For very large CSV files, consider:
- Using
create_table(source=...) which streams data
- Importing in batches if memory is limited
See also