Library cheatsheet
Polars 2 Cheatsheet
Fast DataFrames in Python: expressions, filtering, grouping, joins, lazy queries and file formats.
Basics
- Install Polars — Install the Polars library.
- Create a DataFrame — Build a DataFrame from a dictionary of columns.
- Read a CSV file — Load a CSV into a DataFrame.
- Look at the data — Preview rows, check the schema and summarize numeric columns.
- Select columns — Choose columns by name or expression.
- Filter rows — Keep rows that match a condition. Combine conditions with & and |.
- Add or change columns — Create new columns from expressions. Existing columns with the same name are replaced.
- Sort rows — Sort by one or more columns.
Expressions, grouping and joins
- Group and aggregate — Compute several aggregates per group.
- Conditional columns — Set a value by condition, like CASE WHEN in SQL.
- Join two DataFrames — Combine DataFrames on a key. how can be inner, left, full, semi or anti.
- Handle missing values — Replace nulls, or drop rows that contain them.
- Work with strings — Use the str namespace for text operations.
- Work with dates — Parse text to dates and extract parts with the dt namespace.
- Window functions — Compute a value per group while keeping every row.
- Pivot a DataFrame — Turn values of one column into columns.
Lazy queries and files
- Scan a file lazily — Build a query without loading the file. Polars optimizes it and reads only what it needs.
- Write and run a lazy query — Chain operations on a LazyFrame, then collect the result.
- See the query plan — Print the optimized plan of a lazy query.
- Read and write Parquet — Parquet is compact and fast to read.
- Stack DataFrames — Append DataFrames that have the same columns.
- Convert to and from pandas — Convert for libraries that expect pandas. This needs pyarrow installed.
- Process data larger than memory — Collect with the streaming engine so data is handled in batches.
Related cheatsheets
- Hugging Face cheatsheet — The hf command line, and Transformers and Datasets code for downloading, running, training and sharing models.
- Matplotlib and seaborn 3 cheatsheet — Draw line, scatter, bar and histogram charts with Matplotlib, and statistical charts with seaborn.
- pandas and NumPy 3 cheatsheet — Load, clean, reshape, group and analyze tabular data with pandas, and work with arrays in NumPy.
- Prisma ORM cheatsheet — Model your database in a schema, run migrations, and query with the type-safe Prisma Client. Examples use the prisma-client-js generator; check the docs for newer generators.
- PyTorch 2 cheatsheet — Tensors, autograd, models, training loops, saving and speed-ups in PyTorch 2.
- React 19 cheatsheet — Hooks, components and patterns for React 19 in TypeScript or JavaScript.