DuckDB vs Polars vs pandas: timings on 10 and 100 million rows
The short answer first. We ran the same five queries over Parquet files at 10 million and 100 million rows. On four of them DuckDB and Polars finished within a factor of 1.5 of each other; the fifth is a small filter both answer in under 0.1 seconds. pandas was the slowest on every query, 2 to 23 times slower than the faster of the other two, and needed up to 71 times the memory. DuckDB used the least memory on aggregations and joins.
The rest of this post is the evidence, the code, and what it means for choosing one. The three are not rivals in practice: DuckDB can query a pandas or Polars DataFrame in place, and most notebooks end up using two of them.
The setup
| Machine | Mac mini, 6-core Intel Core i5-8500B, 32 GB RAM, macOS 15.7 |
| Versions | DuckDB 2.0.1, Polars 2.2.0, pandas 3.1.1 with PyArrow 26.0.1, Python 3.15.2 |
| Data | orders: 10 million rows (140 MB of Parquet) and 100 million rows (1.4 GB), sorted by date. customers: 100,000 rows |
| Method | Each query in a fresh process, from the Parquet file to the result. Median of 5 runs at 10 million rows, 3 at 100 million. Memory is the process's peak resident size |
| Settings | Defaults everywhere, all cores available |
The data is generated by DuckDB, so you can rebuild it exactly. Change the row count for the larger file.
COPY (
SELECT range AS order_id,
(hash(range) % 100000)::INTEGER AS customer_id,
((hash(range + 1) % 50000) / 100.0)::DOUBLE AS amount,
DATE '2025-01-01' + (hash(range + 2) % 695)::INTEGER AS order_date,
CASE WHEN hash(range + 3) % 100 < 70 THEN 'paid'
WHEN hash(range + 3) % 100 < 85 THEN 'shipped'
WHEN hash(range + 3) % 100 < 92 THEN 'pending'
WHEN hash(range + 3) % 100 < 97 THEN 'refunded'
ELSE 'cancelled' END AS status
FROM range(10_000_000)
ORDER BY order_date, order_id
) TO 'orders.parquet' (FORMAT parquet);
COPY (
SELECT range::INTEGER AS id,
CASE WHEN range % 10 = 0 THEN 'enterprise'
WHEN range % 10 < 4 THEN 'mid-market'
ELSE 'smb' END AS segment,
['US','GB','DE','FR','TR','NL','ES','IT','SE','PL',
'BR','MX','CA','AU','IN','JP','SG','ZA','AE','IE'][(hash(range) % 20 + 1)::INTEGER] AS country
FROM range(100_000)
) TO 'customers.parquet' (FORMAT parquet);The five queries
- Q1, aggregate: orders and revenue by month and status, 115 groups.
- Q2, selective filter: the orders of one day. The file is sorted by date, so an engine that reads Parquet statistics can skip most of it.
- Q3, join: revenue by customer segment and country, for paid orders.
- Q4, many groups: the top 10 of 100,000 customers by revenue.
- Q5, latest row per key: each customer's most recent order, counted by status. This one has to order every row.
Each library got its idiomatic form: SQL on the files for DuckDB, the lazy API for Polars, and for pandas a read_parquet limited to the columns and row filters the query needs. All three returned the same answers. Here is Q3 in each; all five queries for all three libraries are in the benchmark script: https://thunderduck.ai/blog/polars-pandas/benchmark.py
import duckdb
rows = duckdb.sql("""
SELECT c.segment, c.country, sum(o.amount) AS revenue
FROM 'orders.parquet' o JOIN 'customers.parquet' c ON c.id = o.customer_id
WHERE o.status = 'paid'
GROUP BY ALL ORDER BY ALL
""").fetchall()import polars as pl
df = (
pl.scan_parquet("orders.parquet")
.filter(pl.col("status") == "paid")
.join(pl.scan_parquet("customers.parquet"), left_on="customer_id", right_on="id")
.group_by("segment", "country")
.agg(pl.col("amount").sum().alias("revenue"))
.sort("segment", "country")
.collect()
)import pandas as pd
o = pd.read_parquet("orders.parquet", columns=["customer_id", "amount"],
filters=[("status", "==", "paid")])
c = pd.read_parquet("customers.parquet")
df = (
o.merge(c, left_on="customer_id", right_on="id")
.groupby(["segment", "country"], observed=True)["amount"].sum()
.reset_index(name="revenue")
)Results: 10 million rows
| Query | DuckDB | Polars | pandas |
|---|---|---|---|
| Q1 aggregate | 0.13 s · 111 MB | 0.12 s · 236 MB | 2.00 s · 1,185 MB |
| Q2 one-day filter | 0.05 s · 51 MB | 0.01 s · 60 MB | 0.07 s · 106 MB |
| Q3 join | 0.20 s · 253 MB | 0.14 s · 294 MB | 1.19 s · 994 MB |
| Q4 top 10 of 100,000 | 0.22 s · 241 MB | 0.16 s · 284 MB | 0.48 s · 646 MB |
| Q5 latest per customer | 0.81 s · 875 MB | 0.80 s · 897 MB | 1.79 s · 1,116 MB |
Results: 100 million rows
| Query | DuckDB | Polars | pandas |
|---|---|---|---|
| Q1 aggregate | 1.00 s · 138 MB | 1.24 s · 602 MB | 22.9 s · 9,832 MB |
| Q2 one-day filter | 0.07 s · 61 MB | 0.01 s · 65 MB | 0.10 s · 118 MB |
| Q3 join | 1.43 s · 304 MB | 1.27 s · 571 MB | 13.4 s · 8,495 MB |
| Q4 top 10 of 100,000 | 1.74 s · 284 MB | 1.46 s · 1,985 MB | 3.99 s · 5,265 MB |
| Q5 latest per customer | 8.39 s · 5,877 MB | 8.85 s · 5,784 MB | 18.2 s · 8,345 MB |
What the numbers say
- DuckDB and Polars are a tie on speed. Polars was ahead on Q3 and Q4, DuckDB on Q1 and Q5 at 100 million rows, and the widest gap between them on those four was a factor of 1.5. If speed is your only question, pick the API you prefer.
- Polars wins the tiny query. On the one-day filter Polars answered in about 10 ms and DuckDB in 50 to 70 ms. Both skip most of the file using its statistics; the difference is start-up cost, and it only matters if you run thousands of such queries.
- DuckDB uses the least memory when it can stream. Going from 10 to 100 million rows, its peak for Q1 went from 111 to 138 MB and for Q4 from 241 to 284 MB. Polars grew to 602 MB and 1,985 MB on the same two, pandas to 9.8 GB and 5.3 GB.
- Nobody streams Q5. Ordering every row to find each customer's latest order took about 5.8 GB in both DuckDB and Polars at 100 million rows.
- pandas pays for loading. It reads the columns into memory before it computes, so its time and memory grow with the file, not with the answer. At 100 million rows Q1 took 22.9 seconds against 1.0 for DuckDB.
- pandas is still fine on small data. At 10 million rows its slowest query took 2 seconds, and the gaps shrink with the data.
One pandas detail explains its Q1 time. pandas 3.1 returns a Parquet DATE column as Python date objects (dtype object), and truncating 10 million of those to months took most of the 2 seconds.
They work together
DuckDB reads pandas and Polars DataFrames by variable name, without copying them into a database first, and hands results back as either kind of frame:
import duckdb, pandas as pd, polars as pl
pdf = pd.read_parquet("orders.parquet", columns=["customer_id", "amount"])
plf = pl.read_parquet("orders.parquet", columns=["customer_id", "amount"])
TOP = """
SELECT customer_id, sum(amount) AS revenue
FROM {} GROUP BY customer_id
ORDER BY revenue DESC, customer_id LIMIT 10
"""
top_pandas = duckdb.sql(TOP.format("pdf")).df() # query a pandas frame, get pandas back
top_polars = duckdb.sql(TOP.format("plf")).pl() # query a Polars frame, get Polars backOn the 10-million-row frames, Q4 took 213 ms as a pandas groupby and 145 ms as DuckDB SQL over the same pandas frame; 200 ms as a Polars group_by and 144 ms as DuckDB SQL over the Polars frame. Once the data is in memory the three are close, so the practical pattern is to let DuckDB or Polars do the heavy read and aggregation from files, then hand a small frame to whatever the rest of your code expects, including pandas.
In a notebook
Nothing here needs a server, which is why all three are comfortable in Jupyter and Colab: pip install duckdb polars pandas, and the code above runs in a cell as written. A notebook has one constraint the benchmark machine did not, which is memory you do not control. A free hosted notebook has far less than 32 GB, and the 100-million-row table tells you what happens then: the queries DuckDB streams need a few hundred megabytes, and pandas needs 5 to 10 GB.
When the data is not a file on your machine
Every number above assumes the Parquet file is on local disk. The harder case in a company is that the data sits in a warehouse, a production database and a bucket you have no credentials for. That is the gap thunderduck-sqlalchemy fills: the same DuckDB engine, run on a remote worker sized for each query, against catalogs your role can read, returning a pandas or Polars frame.
# pip install "thunderduck-sqlalchemy[polars]"
import os
from sqlalchemy import create_engine
from sqlalchemy.pool import NullPool
from thunderduck_sqlalchemy import fetch_dataframe
engine = create_engine(
f"thunderduck://:{os.environ['TD_TOKEN']}@api.thunderduck.ai/",
poolclass=NullPool,
)
# The aggregation runs on the engine; the full result comes back as Parquet
df = fetch_dataframe(
engine,
"SELECT region, sum(total) AS revenue FROM sales_pg.public.orders GROUP BY region",
backend="polars", # or "pandas"
)Which local driver to use for a DuckDB file through SQLAlchemy, and how the Thunderduck one differs, is in DuckDB with SQLAlchemy.
PyTorch: from a lakehouse table to a DataLoader
Training data is where the local-copy habit does the most damage: a feature set gets exported once, lands in someone's home directory, and six weeks later nobody can say which snapshot the production model was trained on. Reading features straight from a governed table fixes the provenance problem for free — the query is the lineage.
import polars as pl
import torch
from torch.utils.data import DataLoader, TensorDataset
FEATURES = """
SELECT
tenure_months,
monthly_spend,
support_tickets,
discount_rate,
churned
FROM analytics.gold.customer_features
WHERE snapshot_date = DATE '2026-08-01'
"""
with engine.connect() as conn:
df = pl.read_database(query=FEATURES, connection=conn)
x = torch.tensor(df.drop("churned").to_numpy(), dtype=torch.float32)
y = torch.tensor(df["churned"].to_numpy(), dtype=torch.float32).unsqueeze(1)
loader = DataLoader(TensorDataset(x, y), batch_size=256, shuffle=True)
model = torch.nn.Sequential(
torch.nn.Linear(x.shape[1], 32),
torch.nn.ReLU(),
torch.nn.Linear(32, 1),
)
loss_fn = torch.nn.BCEWithLogitsLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
for epoch in range(10):
for xb, yb in loader:
optimizer.zero_grad()
loss = loss_fn(model(xb), yb)
loss.backward()
optimizer.step()
print(f"epoch {epoch} loss {loss.item():.4f}")Two honest caveats, because they change how you write the query. First, every statement runs as an isolated job, so expect seconds before the first row — this is built for analytics, not for a tight per-batch fetch inside the training loop. Load the feature set once, as above. Second, result sets are row-capped: a page has a ceiling and so does a stored result. Aggregate and filter in SQL rather than pulling raw rows. When you do need every row, fetch_dataframe in the same package downloads the full stored result as Parquet instead of paging it.
For a training set genuinely too large to page back, do what you would do anyway: materialize it once with CREATE TABLE AS into your own bucket, and let PyTorch read those Parquet files directly. Thunderduck built the table, your GPU box reads it at disk speed, and the definition of the feature set still lives in version-controlled SQL rather than in a notebook cell.
Worth remembering what the driver will not do: it is read-only. No DML, no DDL, no transactions — commit() and rollback() are no-ops. Writes belong in a scheduled job or a dbt model, not in the middle of an experiment.
Which one, when
| If | Use |
|---|---|
| You think in SQL, or the data is in files and databases you want to join | DuckDB |
| You think in DataFrame expressions and want lazy, typed pipelines | Polars |
| The data is small, or a library you depend on expects pandas | pandas, fed by one of the other two |
| Memory is the limit | DuckDB for aggregations and joins |
| The data is not on your machine, or several people need the same tables | Thunderduck, returning a pandas or Polars frame |