Q&A library Python

Should I use Polars instead of pandas?

Python Advanced dataframesperformancepolars

Short answer

Polars is a faster DataFrame library with a lazy query engine and no index, which suits large data and long pipelines. Pandas has a far larger ecosystem, so choose Polars for speed and pandas for compatibility.

The short version

Polars is a newer DataFrame library that is typically much faster than pandas, uses multiple cores by default, and offers a lazy mode that optimises a whole query before running it. It has no index, which removes a whole class of pandas confusion. Pandas still wins on ecosystem support. Choose Polars for large data and long pipelines; stay with pandas when you need the wider library support.

The basic shape of Polars code

import polars as pl

df = pl.DataFrame({
    "city": ["Leeds", "Leeds", "Bath"],
    "amount": [1, 2, 3],
})

out = df.group_by("city").agg(pl.col("amount").sum()).sort("city")
print(out.to_dicts())   # [{'city': 'Bath', 'amount': 3}, {'city': 'Leeds', 'amount': 3}]

It reads much like pandas, but you refer to columns through expressions (pl.col("amount")) rather than by bracket indexing, and those expressions are what the engine optimises.

Lazy evaluation is the big idea

In lazy mode, nothing runs until you call collect(). Polars sees the entire pipeline first and can optimise it: pushing filters down so less data is read, and dropping columns you never use.

result = (
    pl.LazyFrame({"a": [1, 2, 3]})
    .filter(pl.col("a") > 1)
    .select(pl.col("a").sum())
    .collect()
)

Pandas runs each step eagerly, materialising an intermediate frame every time. On a long pipeline over large data, the lazy approach avoids a great deal of wasted work, which is where much of the speed difference comes from.

No index

Polars has no index at all. Every column is just a column. This removes the misalignment surprises, the reset_index boilerplate, and the SettingWithCopyWarning confusion that follow from the pandas index. Many people find this alone makes their code simpler.

Where pandas still wins

The ecosystem. Vast numbers of libraries accept and return pandas DataFrames: scikit-learn, statsmodels, most plotting libraries, most tutorials, and most colleagues. Pandas also has a far larger body of documentation and answers. If your work is small enough that speed is not a problem, that compatibility is worth more than raw performance.

They interoperate

You do not have to choose globally. Convert at the boundary when a library needs pandas.

pdf = df.to_pandas()          # Polars -> pandas
back = pl.from_pandas(pdf)     # pandas -> Polars

A practical pattern is to do heavy filtering and aggregation in Polars, then hand a small result to pandas for modelling or plotting.

An honest recommendation

If your data fits comfortably in memory and your pipelines are fast enough, there is no urgent reason to switch, and pandas knowledge remains the more transferable skill. If you are hitting memory limits or waiting on slow groupbys and joins, Polars is very likely to help, and its lazy engine and lack of an index are genuine design improvements rather than just a speed claim.

Need this solved on your own data?

The library is free and always will be. When the problem is bigger than an answer, we take on the work.

Start a project