Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Function

pl.read_csv

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.

How it works

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.

Syntax

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)

Parameters

NameTypeDescription
sourcestr | 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.
columnsSequence[int] | Sequence[str] | NoneColumn positions or names to read; None reads all columns.
has_headerboolWhether the first row contains column names.
separatorstrDelimiter between fields.
schemaSchemaDict | NoneOptional complete schema for the input.
schema_overridesMapping[str, PolarsDataType] | Sequence[PolarsDataType] | NoneType overrides for selected columns.
ignore_errorsboolWhether to ignore rows that cannot be parsed.
try_parse_datesboolWhether to attempt date parsing.
with_column_namesCallable[[list[str]], list[str]] | NoneCallable used to transform parsed column names.

Returns

DataFrame

Key points

  • The function eagerly parses CSV input and produces a Polars DataFrame.
  • source accepts file paths and file-like objects, in addition to bytes and supported sequences.
  • Select columns by integer positions or names with columns.
  • By default, the first CSV row is treated as the header; set has_header to change that behavior.
  • Schema inference examines up to the configured number of rows unless inference is disabled or adjusted.
  • Enable try_parse_dates when date-like values should be parsed into temporal columns.

Common mistakes

  • Input that does not follow RFC 4180 may fail or be interpreted unexpectedly unless a documented option handles the variation.

Example: Read a pipe-separated CSV

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.

When to use it

Local CSV ingestion

Load a local delimited text file into an eager DataFrame for immediate inspection or transformation.

In-memory ingestion

Read an in-memory BytesIO object or raw bytes when data arrives from an API, upload, or test fixture.

Controlled schema and projection

Select only required columns and provide schema overrides to reduce unnecessary parsing and stabilize types.

Multi-file ingestion

Combine matching CSV files by supplying multiple supported sources or a glob-enabled path.

Interview questions

QWhat does polars.read_csv return, and what can source be?

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.

QHow do you adapt parsing and column selection?

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.

QHow are CSV column types determined?

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_csv
  • polars.DataFrame.write_csv
  • polars.LazyFrame.sink_csv

Source: polars.read_csv — Polars documentation. Checked 2026-10-15.