Local CSV ingestion
Load a local delimited text file into an eager DataFrame for immediate inspection or transformation.
Polars · Function
Reads CSV data eagerly into a Polars DataFrame. It supports paths, file-like inputs, bytes, and multiple sources, with options for delimiters, headers, schemas, column selection, and parsing behavior.
Pass a path, bytes, sequence of paths, or file-like object as the source. Configure parsing with keyword arguments such as separator, selected columns, schema controls, date parsing, and error handling; the function eagerly parses the CSV and returns a DataFrame.
polars.read_csv(source, *, columns=None, has_header=True, separator=',', comment_prefix=None, quote_char='"', skip_rows=0, skip_lines=0, schema=None, schema_overrides=None, null_values=None, missing_utf8_is_empty_string=False, ignore_errors=False, try_parse_dates=False, n_rows=None, encoding='utf8', low_memory=False, rechunk=False, skip_rows_after_header=0, row_index_name=None, row_index_offset=0, sample_size=1024, eol_char='\n', raise_if_empty=True, truncate_ragged_lines=False, decimal_comma=False, glob=True, storage_options=None, credential_provider='auto', retries=2, file_cache_ttl=3600, include_file_paths=None, infer_schema=True, infer_schema_length=100, infer_schema_files=10, with_column_names=None, extra_columns=None, missing_columns=None, use_pyarrow=False)| Name | Type | Description |
|---|---|---|
source | str | Path | IO[str] | IO[bytes] | bytes | list[str] | list[Path] | list[IO[str]] | list[IO[bytes]] | list[bytes] | File path, file-like object, bytes, or a supported sequence of these sources. |
columns | Sequence[int] | Sequence[str] | None | Column positions or names to read; None reads all columns. |
has_header | bool | Whether the first row contains column names. |
separator | str | Delimiter between fields. |
schema | SchemaDict | None | Optional complete schema for the input. |
schema_overrides | Mapping[str, PolarsDataType] | Sequence[PolarsDataType] | None | Type overrides for selected columns. |
ignore_errors | bool | Whether to ignore rows that cannot be parsed. |
try_parse_dates | bool | Whether to attempt date parsing. |
with_column_names | Callable[[list[str]], list[str]] | None | Callable used to transform parsed column names. |
DataFrame
import polars as pl
from io import BytesIO
csv = b"name|age\nAda|36\nLinus|55\n"
df = pl.read_csv(BytesIO(csv), separator="|")
print(df)Reads pipe-separated bytes from an in-memory file-like object into a DataFrame.
Load a local delimited text file into an eager DataFrame for immediate inspection or transformation.
Read an in-memory BytesIO object or raw bytes when data arrives from an API, upload, or test fixture.
Select only required columns and provide schema overrides to reduce unnecessary parsing and stabilize types.
Combine matching CSV files by supplying multiple supported sources or a glob-enabled path.
It eagerly reads CSV data and returns a DataFrame. The source may be a path, file-like object, bytes, or a list of supported sources.
Follow-up: How would you read several matching files? Pass a list of paths or supported file-like sources as the source argument.
Use separator to change the field delimiter and columns to select columns by name or integer position. has_header controls whether the first row supplies column names.
Follow-up: How can column names be transformed during reading? Provide with_column_names with a callable that receives and returns the column-name list.
schema defines the complete expected schema, while schema_overrides changes types for selected columns without replacing the full schema. infer_schema and infer_schema_length control whether and how much data is used for inference.
Follow-up: What option helps when inference needs to inspect multiple files? Set infer_schema_files to the number of files used for schema inference.
polars.scan_csvpolars.DataFrame.write_csvpolars.LazyFrame.sink_csv