Reading CSV in Python
read_csv loads eagerly; scan_csv defers so the query planner can help.
from io import StringIO
import polars as pl
RAW = "day,lang,tpm\n2026-07-28,python,104\n2026-07-29,rust,98\n"
frame = pl.read_csv(StringIO(RAW), try_parse_dates=True,
schema_overrides={"tpm": pl.Int32})
print(frame.schema)
print(frame)
with open("runs.csv", "w") as f:
f.write(RAW)
lazy = pl.scan_csv("runs.csv")
print(type(lazy).__name__, lazy.collect_schema().names())
How it works
schema_overridesnames the types you care about.try_parse_datesturns date-looking columns into real dates.scan_csvreturns a LazyFrame and reads nothing yet.
Keywords and builtins used here
asopenprinttypewith
The run, in numbers
- Lines
- 15
- Characters to type
- 374
- Tokens
- 104
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 62 seconds.
Step 3 of 4 in Series & frames, step 3 of 32 in Polars.