Polars is a library for transforming, analyzing, and visualizing data with a fast and expressive DataFrame API. It was first released by Ritchie Vink in 2020.
Install Polars with all of its optional dependencies from the terminal:
uv pip install "polars[all]"
Import Polars in Python, and confirm which versions of Polars and its dependencies you have installed:
import polars as pl pl . show_versions ()
Polars queries typically read data, transform it, and write the result back out. A complete query is often a single chain of method calls:
fruit = pl . read_csv ( "fruit.csv" ) fruit . filter ( ( pl . col ( "weight" ) > 1000 ) & pl . col ( "is_round" ) ) . write_parquet ( "fruit.parquet" )
Throughout this cheatsheet, df is a DataFrame , lf is a LazyFrame , o is a second DataFrame to combine with df , and e stands for any expression. So e.abs() means “call .abs() on an expression”, as in pl.col("x").abs() .
Data Structures#
Polars stores all of its data in either a Series or a DataFrame.
... continue reading