Parallel computation with the pandas API in Dask
Splitting a table into partitions and computing an aggregation on them in parallel.
Goal: Building a query plan that Polars optimises before execution.
import polars as pl
df = pl.DataFrame({
"city": ["بغداد", "البصرة", "بغداد", "الديوانية", "البصرة", "بغداد"],
"sales": [120, 80, 150, 60, 95, 130],
})
q = (df.lazy()
.filter(pl.col("sales") > 70)
.group_by("city")
.agg(pl.col("sales").sum().alias("total"), pl.len().alias("n"))
.sort("total", descending=True))
print(q.collect())
With lazy() nothing runs until collect(), so Polars fuses filtering and aggregation and reads only the needed columns. This is what makes it faster than pandas on large tables.
shape: (2, 3) ┌────────┬───────┬─────┐ │ city ┆ total ┆ n │ │ --- ┆ --- ┆ --- │ │ str ┆ i64 ┆ u32 │ ╞════════╪═══════╪═════╡ │ بغداد ┆ 400 ┆ 3 │ │ البصرة ┆ 175 ┆ 2 │ └────────┴───────┴─────┘
This example was actually run and tested on 21 November 2026 on a CPU — polars 2.1.0, python 3.13.18
Splitting a table into partitions and computing an aggregation on them in parallel.
Sections
No section has this name. Press “Search” to search all site content.
Favourites
My results & certificates
My academy progressMy quiz resultsKids’ progressAcademy certificatesQuiz certificatesStart any lesson or quiz and it will show up here so you can get back to it quickly.
Settings
I am the AI Frameworks & Libraries Assistant. Describe your project or ask me about a library, a comparison or a code example, and I will answer from the encyclopedia's database with links and sources.
Answers from the encyclopedia's database only, without a language model and without sending your question to any third party.
The assistant can make mistakes, so check the attached sources.