Skip to content
Tutorials Center
My learning

Topics

Polars Tutorial

Learn Polars step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Polars? Learn what Polars is, how its Rust engine, expressions and lazy evaluation differ from other DataFrame tools, and when to choose it for your data work.
  2. 2 Your First DataFrame Create a Polars DataFrame, inspect its shape, schema and columns, peek at rows with head, tail and glimpse, and read values back out as Python objects.
  3. 3 Data Types Understand Polars data types: integers, floats, strings, booleans, dates, categoricals, lists and structs, plus casting, schemas and choosing smaller types.
  4. 4 Display Settings and Reading Output Control how Polars prints tables with pl.Config: number of rows and columns, string width, table formatting, and how to read the shape and dtype header.
  5. 5 Core Contexts: select, filter, with_columns Learn Polars contexts: select, with_columns, filter, group_by and sort, how each one evaluates expressions, and how to chain them into readable pipelines.

DataFrames and Series

  1. 6 Series Basics A Polars Series is one typed column. Learn to create Series, use arithmetic and aggregations, inspect dtype and length, and move between Series and DataFrames.
  2. 7 Creating DataFrames Build Polars DataFrames from dictionaries, lists of rows, records, NumPy arrays and pandas, control orientation and schema, and handle mixed-type errors.
  3. 8 Selecting and Slicing Pick columns and rows in Polars with select, drop, bracket indexing, slice, head, tail, gather and row access, and learn why select is preferred over indexing.
  4. 9 Filtering and Sorting Keep and order rows in Polars with filter, boolean expressions, is_in, is_between, sort with multiple keys, unique, duplicates, sample and top_k.
  5. 10 Null and NaN Values Handle missing data in Polars: the difference between null and NaN, detecting, counting, filling and dropping nulls, and how nulls behave in comparisons and sums.

Expressions

  1. 11 Expression Basics Learn Polars expressions from the ground up: pl.col, pl.lit, arithmetic, aliasing, aggregations, chaining, expression expansion, and why expressions are fast.
  2. 12 String Expressions Clean and transform text in Polars with the str namespace: case, strip, contains, regex extract, replace, split, slicing, padding, parsing and concatenation.
  3. 13 Date and Time Expressions Work with dates in Polars: Date and Datetime types, parsing, the dt namespace, truncation, arithmetic with durations, time zones, date ranges and rolling windows.
  4. 14 When, Then, Otherwise Create conditional columns in Polars with when, then and otherwise: chained branches, multiple conditions, null handling, cut and bucketing, and replace_strict mapping.
  5. 15 Column Selectors Select columns by type, name pattern or position with polars.selectors (cs), combine them with set operations, and apply one expression to many columns.
  6. 16 List and Struct Columns Work with nested data in Polars: List columns, the list namespace, explode, Struct columns, unnest, field access, building structs and per-row list aggregation.

Lazy Evaluation

  1. 17 Lazy Frames: the Basics Learn Polars lazy evaluation: create a LazyFrame with lazy() or scan_csv, chain operations, check schemas, and run the optimized plan with collect.
  2. 18 Query Plans and the Optimizer Read Polars query plans with explain, compare optimized and unoptimized plans, understand predicate, projection and slice pushdown, and switch optimizations off for debugging.
  3. 19 Lazy Pipelines and Streaming Build reusable lazy pipelines in Polars with pipe and functions, run several queries with collect_all, and process data larger than memory with the streaming engine and sinks.

Joins, Groups and Windows

  1. 20 Joins in Polars Combine tables with DataFrame.join in Polars. Learn inner, left, full, semi, anti and cross joins, different key names, suffixes, validation and as-of joins.
  2. 21 group_by and Aggregations Summarize data per group with Polars group_by and agg. Learn multiple aggregations, filters inside agg, group order, dynamic time windows and group-level tricks.
  3. 22 Window Functions with over() Learn Polars window functions with over(): group-relative values, shares, ranks, running totals, lag and lead, and rolling averages without losing any rows.
  4. 23 Pivot, Unpivot and Concatenation Reshape tables in Polars: pivot long data wide, unpivot wide data long, stack and glue frames with concat, and turn list columns into rows with explode.

IO and Formats

  1. 24 Reading and Writing CSV Read and write CSV files with Polars. Control separators, headers, types, null markers, dates and bad rows, then learn the lazy scan_csv for large files.
  2. 25 Parquet, JSON and Arrow IPC Pick the right file format for Polars: Parquet for storage, Arrow IPC for speed, JSON and NDJSON for exchange. Learn the read/write calls and trade-offs.
  3. 26 Interoperability: pandas, NumPy, Arrow and SQL Move data between Polars and pandas, NumPy, Arrow, Python dicts and databases. Learn from_pandas, to_numpy, zero-copy rules, SQLContext and how to read SQL tables.

Performance

  1. 27 Data Types and Memory Shrink Polars DataFrames and speed up queries by choosing smaller integer and float types, Categorical and Enum for repeated text, and measuring size with estimated_size.
  2. 28 Query Plans and Optimizations Read Polars query plans with explain(), see predicate and projection pushdown at work, learn what the optimizer rewrites, and profile a lazy query step by step.
  3. 29 Fast Patterns and Common Slow Spots Write fast Polars code. Avoid row loops and map_elements, batch work into one with_columns, use when/then, joins instead of lookups, and know streaming and thread settings.

Migrating from pandas

  1. 30 pandas to Polars: The Cheat Sheet Translate pandas code to Polars. Side-by-side examples for selecting, filtering, new columns, sorting, groupby, merge, missing values, strings, dates and apply.
  2. 31 Concepts That Differ from pandas Learn the real differences between Polars and pandas: no index, null instead of NaN, strict types, immutable frames, expression contexts, null ordering and ddof defaults.
  3. 32 Migrating a pandas Pipeline Step by Step Port a real pandas cleaning and reporting script to Polars step by step, check that the results match, convert it to a lazy query, and plan a safe gradual migration.

Projects and Practice

  1. 33 Project: A Sales Analysis Report Build a complete sales report with Polars. Generate data, clean it, join products and customers, compute KPIs, monthly growth, top products per region and customer segments.
  2. 34 Project: Web Server Log Analysis Parse raw web server log lines with Polars string expressions and regex, then find top pages, error rates per minute, slow endpoints, busy clients and user sessions.
  3. 35 Project: Sensor Time Series Clean noisy sensor readings with Polars. Fill missing hours, interpolate gaps, resample to daily summaries, flag anomalies with rolling statistics and compare sensors.
  4. 36 Practice: Ten Polars Exercises with Solutions Ten hands-on Polars exercises with runnable solutions covering select, filter, new columns, strings, dates, group_by, joins, window functions, pivot and null handling.
  5. 37 Practice: Harder Polars Challenges Ten harder Polars problems with runnable solutions and explanations: keep latest rows, streaks, tag counts, running balances, top-N per group, forward fill, pair finding and more.